So I made a Bool value, and I want it to go false when a player dies, but it's not going well with me. Can you help? I'd appreciate it if you can!
h = script.Parent:FindFirstChild("Humanoid") player = h:GetPlayerFromCharacter(script.Parent.Parent) x = player:FindFirstChild("Ingame") if h.Health == 0 then x.Value = false end
Humanoid.Health
is a floating-point value, (aka a Number), so it will most likely never be exactly 0. Also, there exists a Died
event for Humanoids, so you don't have to check the health at all. GetPlayerFromCharacter
is a method of Players, not a Humanoid.
Really, this could be better done using the PlayerAdded
and CharacterAdded
Events, so I'll give you a fixed version of your code, and a version using those two:
h = script.Parent:FindFirstChild("Humanoid") if h then player = Game.Players:GetPlayerFromCharacter(script.Parent.Parent) if player then x = player:WaitForChild("Ingame") --Safer than FindFirstChild, will yield the thread until Ingame exists. h.Died:connect(function() x.Value = false end) end end
Game.Players.PlayerAdded:connect(function(player) local x = player:WaitForChild("Ingame") player.CharacterAdded:connect(function(character) wait() --Wait for the character to fully load. character.Humanoid.Died:connect(function() x.Value = false end) end) end)