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

Script continues to run after Destroy()?

Asked by 7 years ago
Edited 7 years ago

I'm really confused. I simply wanted a script to destroy its parent (and itself), that's all. You can find the rest of my code here.

You can easily notice this part (I added parent here):

if not closeEnough then
    script.Parent:Destroy()
end

The problem is, it says that parent is nil. So I did this:

if not closeEnough then
    if script.Parent then script.Parent:Destroy() else script:Destroy() end
end

The results were slightly strange, so I added an error function:

if not closeEnough then
    if script.Parent then script.Parent:Destroy() else script:Destroy() end
    error("my life is a lie")
end

And guess what.

my life is a lie

1 answer

Log in to vote
3
Answered by 7 years ago
Edited 6 years ago

ROBLOX is weird.

You can use return. Example:

do
    return
end
print(1) -- wont print
0
I can return even if it's not inside a function? Programical 653 — 7y
1
do return end print('a') :P User#5423 17 — 7y
Ad

Answer this question