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

Problem with Health GUI?

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

✓ Accepted answer

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)


2 comments

0

mark it as an answer if it works

0

Thanks it works! You just helped me make a successful Health GUI! Thank you soooo much ;D

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