最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

lua - How to delete clones - Roblox Studio? - Stack Overflow

programmeradmin3浏览0评论

I want to build a lag game and I want that when you click a button, all the clones of the part will be gone but when I script it, it's not working. This code is for cloning the part (this is a normal script in a part):

while true do
    wait()
    local clonepart = script.Parent:Clone()
    clonepart.Parent = game.Workspace
    clonepart.Anchored = false
end

This is the code for deleting (a local script in a Text button GUI):

local part = game.Workspace.cloner

script.Parent.MouseButton1Up:Connect(function()
    part:Destroy()
end)

It is removing the part which is making the clones.

I want to build a lag game and I want that when you click a button, all the clones of the part will be gone but when I script it, it's not working. This code is for cloning the part (this is a normal script in a part):

while true do
    wait()
    local clonepart = script.Parent:Clone()
    clonepart.Parent = game.Workspace
    clonepart.Anchored = false
end

This is the code for deleting (a local script in a Text button GUI):

local part = game.Workspace.cloner

script.Parent.MouseButton1Up:Connect(function()
    part:Destroy()
end)

It is removing the part which is making the clones.

Share Improve this question edited Mar 17 at 12:58 Wolf 10.3k8 gold badges68 silver badges112 bronze badges asked Mar 15 at 6:14 aadidev gaadidev g 231 silver badge6 bronze badges 2
  • thanks Kylaaa but I want part to start cloning again after it gets deleted – aadidev g Commented Mar 18 at 9:20
  • Keep a copy of the spawning block in ReplicatedStorage and write a spawning script in ServerScriptService that clones the block into the Workspace – Kylaaa Commented Mar 18 at 11:30
Add a comment  | 

2 Answers 2

Reset to default 3

The easiest way to remove everything with one line would be to put all of the clones into a Folder in the Workspace. Then when you click the button, you fire a RemoteEvent to tell the server to simply destroy the Folder and/or all of its children.

So try something like this :

  1. Have your spawner block create a Folder for all of its clones in the Workspace called LagFolder
  2. Create a RemoteEvent in ReplicatedStorage called DestroyLagFolder
  3. Have the LocalScript that listens to your your mouse button events fire the RemoteEvent.
local DestroyLagFolderEvent : RemoteEvent = game.ReplicatedStorage.DestroyLagFolder

script.Parent.MouseButton1Up:Connect(function()
    -- tell the server to destroy all the spawned clones
    DestroyLagFolderEvent:FireServer()
end)
  1. Have the part spawner Script listen for when the RemoteEvent event gets fired.
local PART_SPAWN_TIME = 1 --second

-- create a place for all of the clones to go
local LagFolder = Instance.new("Folder")
LagFolder.Parent = game.Workspace

-- listen for when the event fires to clean up all of the clones and the spawner
local DestroyLagFolderEvent : RemoteEvent = game.ReplicatedStorage.DestroyLagFolder
DestroyLagFolderEvent.OnServerEvent:Connect(function(player)
    LagFolder:Destroy()
    script.Parent:Destroy()
end)

-- start creating clones
while wait(PART_SPAWN_TIME) do
    local clonepart = script.Parent:Clone()
    clonepart.Parent = LagFolder
    clonepart.Anchored = false
end

Better context? Only suggestion I have is to simply change MouseButton1Up to MouseButton1Down.

发布评论

评论列表(0)

  1. 暂无评论