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

My Health System Doesn't work online?

I am trying to make a custom health system that displays names of players. I need this a lot in scripting so I'd like to get it out of the way. Please and thank you.

Player = game.Players.LocalPlayer
script.Parent.Text = Player.Character.Humanoid.Health
script.Parent.Parent.PlayerName.Text = Player.Name

1 comment

0

change it into a local script

1 answer

I'm assuming this is because you're not waiting for the player's Character to load.

In a server, things take a while to load. When making scripts, especially Local Scripts, it's important to use WaitForChild.

In your case however, we're going to use the Character Added Event.

--Local Script, Probably in StarterGui/PlayerGui

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")

script.Parent.Text = Humanoid.Health
script.Parent.Parent:WaitForChild("PlayerName").Text = Player.Name

I also Waited for the Humanoid to load and PlayerName to load.

Possible problems,

The Health Property of the Humanoid is a Int/Number Value, not a string. This shouldn't matter because rbx.Lua should make it into a string, but just in case I'm going to use the tostring function to make Humanoid.Health into a string,

--Local Script, Probably in StarterGui/PlayerGui

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")

script.Parent.Text = tostring(Humanoid.Health)
script.Parent.Parent:WaitForChild("PlayerName").Text = Player.Name

That might make the script a little larger. If you wanted to shorten your script, you don't really have to use variable, but I would recommend it.

I hope I helped!

Good Luck!

If I did help, don't forget to accept this answer!

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