Script not working

My goal of this script:
to make an object move when a player touches it (working)
and make the object move back when the player who touched it dies (not working)

	game.Workspace.LeaderSeat.Touched:connect(function(player)
	wait(0)
	script.Parent.Position = Vector3.new(48.019, -8.126, 155.132)
	wait(0)
	
	if player.health == 0 

	then
		wait(0)
		script.Parent.Position = Vector3.new(48.019, 1.874, 155.132)
		wait(0)
		
	end
end)

thank you.

1 Like

Just do a died event. Plus what would wait(0) do exactly? Also use task.wait so it’s more on time.

player.Humanoid.Died:Connect(function()

end)

Also check if they have a humanoid since anything inside their character is in the client’s hands so exploiters can error your script.

accidently did not add the full script first.
updated it.

this is the same function I previously used, maybe I typed it wrong, but it did not work.

Do this

If humanoid.Health <= 0 then
      --- function
end
1 Like

There is a premade RBXScriptEvent for detecting when a humanoid dies, Humanoid | Roblox Creator Documentation.
Also a .Touched event returns the Part that touched it not the player

Thank you. I changed humanoid to player.
new script:

game.Workspace.LeaderSeat.Touched:connect(function(player)
	wait(0)
	script.Parent.Position = Vector3.new(48.019, -8.126, 155.132)
	wait(0)
	
	if player.Health <= 0 
	then
		wait(0)
		script.Parent.Position = Vector3.new(48.019, 1.874, 155.132)
		wait(0)
		
	end)
end)

You should change player to humanoid

That will run right away and not again, so what if they weren’t dead as they touched the part?

check if humanoid’s health higher than 0?

If you want it to be cooler, you should try adding in the TweenService and maybe looking up a tutorial on how to do that.