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

Anyone know why this LocalScript is only changing the IntValue once?

Asked by
F_lipe 135
7 years ago

So this script is meant to use the value of an IntValue I created to decide how big or small the health bar I have created is (the healthbar is a gui, health is inside the localplayer)

this works, in fact, the script runs without errors. But it only changes the size of the gui once and that is to whatever i predetermine the health value to be before I run the game. Any reason for this? Am I calling for anything improperly/does something I call change locations post-player connection?

Here is my code, any help is appreciated:

local player=game.Players.LocalPlayer
local health=player.Health.Value
local mana=player.Mana.Value
local character=player.Character

local function changeHealth()
    local health_frame=script.Parent.Gui.Frame.healthFrame
    health_frame.Size = UDim2.new(0, health, 0, 20)
    print("Done")

end

while wait(.1) do
    changeHealth()
end

1 answer

Log in to vote
1
Answered by 7 years ago

Its because you define the 'health' variable at the beginning of the script, locking it in to whatever the value of health was at that moment. In order to fix this, you need to move the line

local health=player.Health.Value

inside your changeHealth function.

0
Sorry for such a late response, just woke up! But thank you! I was not that aware of the importance of where you call the function it works great now. F_lipe 135 — 7y
Ad

Answer this question