It is supposed to show your health (Digits) But doesn't It is in the Starter GUI, then a frame, then the script is in a Text in the Frame.
Player = script.Parent.Parent.Parent.Parent.Parent Character = script.Parent.Parent.Parent.Parent.Parent.Character while true do wait(0.1) script.Parent.Text = math.floor(Character.Humanoid.Health) end
Based on your explanation your hierarchy is like this?
StarterGui Frame TextLabel Script
Well your first obvious problem is that the Frame
is not inside a ScreenGui
instance. All GUI object must be inside a ScreenGui
is order to be shown. Second, the Script should be a LocalScript, because it's the descendant of a player.
Other than that, I don't see anything wrong with your script, syntax speaking. There are, however, ways you could make it more readable and more efficient and less glitchy - some of which may be the reason the code is not working.
For example, make your variables local. It's also normally considered the preferred style to make variables lowercase, so that they are more easily distinguished from methods, properties, etc.
Also since you already have a Player
variable defined, there is no need to parent all the way up to the player a second time for Character
. You need to make sure that the character is loaded, however, before creating the variable, to prevent errors.
Instead of a while
loop, it would be better to use the HealthChanged
event of Humanoid.
local player = script.Parent.Parent.Parent.Parent.Parent repeat wait() until player.Character local character = player.Character character.Humanoid.HealthChanged:connect(function() script.Parent.Text = character.Humanoid.Health end)