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

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

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!

2 comments

0

What does "not working" mean? Is there an error?

0

Well yes. Output says: "Is not a valid member of workspace,"

1 answer

✓ Accepted answer

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

2 comments

0

Thx

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.)

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