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

Problem with Health GUI?

Asked by 9 years ago

It says that Character is a nil value. This script works in solo but not in server :(

player = game.Players.LocalPlayer
mouse = player:GetMouse()
bar = script.Parent
holding = false

player.Character.Humanoid.Changed:connect(function()
    bar.Size = UDim2.new(player.Character.Humanoid.Health / player.Character.Humanoid.MaxHealth, 0, 1, 0)
end)

Please help!

1 answer

Log in to vote
2
Answered by 9 years ago

The thing is, the Character loads a little bit after the Player does. So, if we add repeat wait() until player.Character then the script will function as a Character is detected.

repeat wait() until game.Players.LocalPlayer.Character
player = game.Players.LocalPlayer
mouse = player:GetMouse()
bar = script.Parent
holding = false

player.Character.Humanoid.Changed:connect(function()
    bar.Size = UDim2.new(player.Character.Humanoid.Health / player.Character.Humanoid.MaxHealth, 0, 1, 0)
end)


0
mark it as an answer if it works HungryJaffer 1246 — 9y
0
Thanks it works! You just helped me make a successful Health GUI! Thank you soooo much ;D Alucifer 45 — 9y
Ad

Answer this question