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

Why isn't this auto destroy when owner dies script not working?

Asked by 9 years ago

Idk wut to say Script:

while true do
    owner = script.Owner.Value
    wait()
    if game.Workspace[owner].Humanoid.Health == 0 then
        script.Parent.Parent:Destroy()
    end
end

Its not working. I really need help!

0
What does "not working" mean? Is there an error? BlueTaslem 18071 — 9y
0
Well yes. Output says: "Is not a valid member of workspace," Operation_Meme 890 — 9y

1 answer

Log in to vote
1
Answered by
Minifig77 190
9 years ago

Instead of doing an infinite loop, I'd use an event listener instead:

if game.Workspace[owner] then --Check if game.Workspace[owner] exists
    game.Workspace[owner].Humanoid.Died:connect(function() --Wait until death
        script.Parent.Parent:Destroy() --Destroy script.Parent.Parent
    end)
end

0
Thx Operation_Meme 890 — 9y
0
Also, in case it doesn't work, I had to edit it to add a parentheses (You might have copied the code without them.) Minifig77 190 — 9y
Ad

Answer this question