The GUI's inside StarterGui are replicated intoa player's PlayerGui when they join. The reason as to why it didn't work is because you were trying to change the Text inside the UI in StarterGui, not the one that the client can see. To change this, you may change your script to:
local text = game.Players.LocalPlayer.PlayerGui.SnailHealth.hp
local snailhp = workspace.snail.Humanoid.Health
local snailmaxhp = workspace.snail.Humanoid.MaxHealth
text.Text = tostring(snailhp).."/"..tostring(snailmaxhp)
This is a screenshot showing what my Explorer looks like.
This is a screenshot showing what the Text says when I hit Play.
To update the text to always say its health, you can add a function.
workspace.snail.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
snailhp = workspace.snail.Humanoid.Health
text.Text = tostring(snailhp).."/"..tostring(snailmaxhp)
end)
This function uses GetPropertyChangedSignal, to make it run every time the Health changes.
By the end, the script should look something like:
local text = game.Players.LocalPlayer.PlayerGui.SnailHealth.hp
local snailhp = workspace.snail.Humanoid.Health
local snailmaxhp = workspace.snail.Humanoid.MaxHealth
text.Text = tostring(snailhp).."/"..tostring(snailmaxhp)
workspace.snail.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
snailhp = workspace.snail.Humanoid.Health
text.Text = tostring(snailhp).."/"..tostring(snailmaxhp)
end)
2 comments
do you get any errors? in line 1, it seems like you added too many brackets.
i got it figure out