Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with Clone Destroy?

I am trying to figure out how I can create a map loading system for my game. This is the script I was using to test. This almost works but once the map has been removed from workspace it cannot be re-parented. How would I make it possible to re-parent the map to workspace? Here was my test.

local trench = game.ServerStorage.TrenchMap:Clone()
local Test = game.ServerStorage.LoadMapTest:Clone()

while wait() do
	trench.Parent = workspace
	wait(5)
	trench:Destroy()
	wait(1)
	trench.Parent = workspace
	wait(5)
	trench:Destroy()
	wait(1)
	Test.Parent = workspace
	wait(5)
	Test:Destroy()
end

This is not the actual map loading system. This was a test.

2 answers

✓ Accepted answer

Rather than doing trench:Destroy or Test:Destroy you can set their Parent properties to nil, which will allow you to re-parent them later. trench.Parent = nil, Test.Parent = nil

2 comments

0

This isn't ideal, because if he keeps reusing that and collateral damage happens to the map then it will carry to when he reuses the map.

0

Someone answered this question in the chat about 10 minutes after posting this. I don't remove it from the game anymore. I just move my maps back and forth from workspace to serverstorage. This still has the disadvantages as posted by aquathorn but unless my game is to be hacked my maps will not take damage. Thanks for your help.

The Destroy method sets the parent to nil, and locks that property so it cannot be brought back. To get around this, you could replace Destroy with Remove, which sets the parent to nil but doesn't lock it, or just set it to nil yourself.

Changing it that way isn't ideal though, because it will keep reusing the clone. That means if the clone takes any damage, the damaged map will be reused when it loads again. To combat this, just clone the map again whenever you're about it load it to workspace.

while wait() do
    local trench
    local Test

    trench = game.ServerStorage.TrenchMap:Clone()
    trench.Parent = workspace
    wait(5)
    trench:Destroy()
    wait(1)
    trench = game.ServerStorage.TrenchMap:Clone()
    trench.Parent = workspace
    wait(5)
    trench:Destroy()
    wait(1)
    Test = game.ServerStorage.LoadMapTest:Clone()
    Test.Parent = workspace
    wait(5)
    Test:Destroy()
end

This discussion is preserved as it was. New answers, comments, and votes are closed.