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

I'm currently trying to change a textlabel to a humanoid's hp, but i have an issue. How do i fix?

Asked by 2 years ago

I'm currently trying to get it so where a text label is displaying a humanoid health, using this code in a script.

    local PlayerService = game:GetService('Players') -- wunga bunga

    local Player = PlayerService.LocalPlayer -- wh
local PlayerGui = Player:WaitForChild('PlayerGui') -- "I'll take a double triple bossy deluxe, on a raft, four-by-four animal-style, extra shingles with a shimmy and a squeeze, light axle grease, make it cry, burn it, and let it swim."
    local ScreenGui = PlayerGui:WaitForChild('SnailHealth') -- bb


bingus = game.Workspace.Snail.Humanoid
while true do

    script.Parent.Text = ("Snail HP:" .. bingus.Health)

end

for some reason, this doesn't seem to be working. I'm new to programming in this language. And yes, i actually put it in a local script, and i THINK i am changing the actual playergui. **P.S you have full permission to make a joke about the messages and the Bubble Bass order.

-Cheers, CheemsTheReaper

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

Since you are new to scripting then I will be directly fixing your problem instead. So instead of trying to update the GUI using while true do, you should update it when the snail health changes:

local bingus = game.Workspace.Snail.Humanoid

bingus.HealthChanged:Connect(function()
    script.Parent.Text = "Snail HP:" .. bingus.Health
end)

Why not use while true do? While true do is faster than sonic that it can possibly crash, and make the whole script stops and it's definitely not a good choice.

Also the code above is the entire script you need, you've never used the ScreenGui variable so I didn't add them in. Anyways that code will do is make the script.Parent.Text to the Snail HP text thing when the "bingus" health is changed.

I also have permission to make a joke about the messages and the Bubble Bass order but it was random so I didn't add it. Comment if work and comment if not work. Thanks and have a good day and happy christmas

0
merry christmas to you, godspeed my man CheemsTheReaper 2 — 2y
Ad

Answer this question