In this code I’m writing, I attempt to set an ObjectValue to nil once a player, the value, dies.
local holder = script:WaitForChild("holder")
holder.Changed:Connect(function()
if holder.Value ~= nil then
holder.Value:FindFirstChild("Humanoid").Died:Connect(function()
holder.Value = nil
end)
end
end)
However, it just doesn’t get set to nil. How would I do this?
Ahhh… I see. So they can just STOP the code from working and become invincible. Thanks for pointing that out.
Maybe one could put like a serverside variable for that player’s health and check it whenever it changes. If it’s <= 0 then player has died. Server breaks joints. Whenever the value changes send the value by remoteevent to the player and have their health has changed and update the Humanoid.Health with the server value. They can then keep their Humanoid.Health above 0 but the server won’t care what their Humanoid.Health is.
Yep! There’s actually a HealthChanged event for Humanoids which would do exactly that. The client Humanoid definitely can’t control health and the Died event appears to be fired on the server now (it used to be much less reliable) so I’d say that relying on these are probably alright.
To be honest custom health controllers aren’t a bad idea either. They definitely give you more control.