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

How do i use the destroy function properly?

Okey so I wrote this script that clones objects from the server storage and spawns them randomly and it works flawlessly. My problem is getting the object to go away. Inside the object I have this script and it won't seem to work.

if script.Parent == game.Workspace then
	wait(3) 
	script.Parent:Destroy()
end

1 answer

✓ Accepted answer

You are cloning objects. I assume the script is inside the cloned object. Here's the problem:

script.Parent should be the object, not game.Workspace, the condition will never be true, secondly you would be destroying Workspace if that wasn't the case and that's not possible. Change the snippet to

if script.Parent.Parent == game.Workspace then
    wait(3) 
    script.Parent:Destroy()
end

1 comment

0

Oh lol thanks

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