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

Scripts are not reading health right?

Asked by 9 years ago

I have turned the health coregui off and am trying to make my own gui, but when I run it it displays a bunch of random numbers.

health lower script:

local healthValue = 100

while healthValue > 0 do
    healthValue = healthValue - 5
game.Players.LocalPlayer.Character.Humanoid.Health = healthValue
wait(5)
end

health reading script:

local textValue = script.Parent
local healthValue = game.Players.LocalPlayer.Character.Humanoid
local value = 0
while true do
    value = healthValue.Health
textValue.Text = (value)    
    wait (1)
end

1 answer

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

I'm not sure why that's displaying random numbers, but your health reading script is woefully inefficient.

Try this code instead, using the HealthChanged Event of Humanoid. I've also included a safeguards against stuff loading slowly the first time the Character spawns in:

local Player = Game.Players.LocalPlayer
if not Player.Character then Player.CharacterAdded:wait() end

Player.Character.Humanoid.HealthChanged:connect(function(hp)
    script.Parent.Text = hp
end
2
I would also make sure you round up/down the health value to make it an integer, so that when your health is regenerating, it doesn't show it as a long decimal number. Spongocardo 1991 — 9y
Ad

Answer this question