Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.