Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Not showing health for all players?

Asked by 8 years ago

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

0
Please write what "working" means. Unclear 1776 — 8y

2 answers

Log in to vote
2
Answered by 8 years ago
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

Ad
Log in to vote
1
Answered by 8 years ago
--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.

Answer this question