Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not showing health for all players?

Hi I have been trying to script a game and I got help with this script, but it only works in a test server with one player. It doesn't work on a server with 2 or more players. Can you help?

humanoid = game.Players.LocalPlayer.Character.Humanoid
function round1Place(x)
    return (x + 0.05 - (x + 0.05)  % .1)
end

while wait() do  
    script.Parent.Text = "You have " .. round1Place(humanoid.Health) .. " health left" 
end

1 comment

0

Please write what "working" means.

2 answers

✓ Accepted answer
repeat wait() until game.Players.LocalPlayer.Character -- The Character loads a little while after the Player, so this will be nil. To change that, we add this. This keeps waiting until a Character is detected.
humanoid = game.Players.LocalPlayer.Character.Humanoid
function round1Place(x)
    return (x + 0.05 - (x + 0.05)  % .1)
end

while wait() do  
    script.Parent.Text = "You have " .. round1Place(humanoid.Health) .. " health left" 
end

--I have added an event so that multiple people could be seen working with the humanoids health
game.Players.PlayerAdded:connect(function(player)
humanoid =player.Character.Humanoid
function round1Place(x)
    return (x + 0.05 - (x + 0.05)  % .1)
end

while wait() do  
    script.Parent.Text = "You have " .. round1Place(humanoid.Health) .. " health left" 
end
--If this helped don't forget to leave a upvote or an accept.

This discussion is preserved as it was. New answers, comments, and votes are closed.