Could I use this?
p = game.Players.LocalPlayer.Humanoid.Health if p= 10 then print("Player is a bout to die!")
I always had trouble with LocalPlayers and stuff... so can somebody help me? Thanks!
This is probably what you're looking for. The way it was done before was not only wrong even if it was correct it would have only ran once therefore never printing unless you disabled and enabled the script exactly when the health is 10(near impossible).
local plr = game.Players.LocalPlayer if not plr.Character then plr.CharacterAdded:wait() end local char = plr.Character local hum = char:WaitForChild("Humanoid") hum.HealthChanged:connect(function(health) if health <= 10 then print("Player is about to die!") end end)
Note: This should be a local script in StarterPack.
Pretty much. Just some minor errors, and you're good. Try this:
p = game.Players.LocalPlayer.Humanoid.Health if p== 10 then print("Player is a bout to die!") end
Players.LocalPlayer is a local field, so you need to do this from a LocalScript, not a regular Script.
There are several ways to do this, but you always use the Health property of the Humanoid that is inside the character of a player.
In the example you gave, you forgot to go into the Character and instead you're looking for a Humanoid inside the Player, which is not there. This is the improved script:
p = game.Players.LocalPlayer.Character.Humanoid.Health if p == 10 then -- always use the == operator in comparisons. Remember: == means "equals to", = means "set to" print("Player is about to die!") end -- also, don't forget to end your if statement!