Hi! I’m trying to make a totem of undying-like tool that prevents the player from dying once their health reaches 0 or below. I don’t really know how to accomplish this, so I would appreciate any help you guys could give me. My first attempt was this:
repeat
wait(.001)
until character.Humanoid.Health <= 0
character.Humanoid.Health = 100
Again, I just wanna find a way to prevent a player from dying once their health drops below zero ;-;
You could try using the Humanoid’s SetStateEnabled function to set the “Dead” state to false so they never enter it when they have the totem. And set it back to true again when they don’t have the totem. When a Humanoid’s health hits 0 they enter the Dead state, so disabling that state should keep them alive I think. In bed about to pass out or I’d try it and check.
i did some testing to confirm it as well:
-server- (in ServerScriptService)
--services--
local PlayerService = game:GetService("Players")
--events--
PlayerService.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if Humanoid then
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
end
end)
end)
-client- (in StarterCharacterScripts)
local Hum = script.Parent:FindFirstChildOfClass("Humanoid")
Hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
a silly mistake i did while testing was forgetting to enable the local script, which would result in the player’s character dying normally, but never respawning. after enabling it, it worked for me.
It is good practice to use task.wait(), but there aren’t really problems with wait() except for a bit of throttling and waiting for incorrect time (by less than a second)