Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i use the destroy function properly?

Asked by 10 years ago

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

Log in to vote
0
Answered by
Destrings 406 Moderation Voter
10 years ago

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
0
Oh lol thanks reteach 0 — 10y
Ad

Answer this question