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

Thirst/Hunger bar not changing?

I have made a thirst and hunger bar, but their bars do not change. I am getting no errors in the output either. Can someone tell me what I am doing wrong?

Player = script.Parent.Parent.Parent.Parent
Character = Player.Character

Thirst = 100
Hunger = 100

while true do
	script.Parent.frameThirst.statThirst.Size = UDim2.new(Thirst*0.01, 0, 1, 0)
	script.Parent.frameHunger.statHunger.Size = UDim2.new(Hunger*0.01, 0, 1, 0)
	script.Parent.frameHealth.statHealth.Size = UDim2.new(Character.Humanoid.Health*0.01, 0, 1, 0)
	wait()
end

while true do
	Thirst = Thirst -1 
	Hunger = Hunger -1
	wait(3)
end

1 comment

0

UPDATE: I did find that the bars are working. Only thing is, the values will not change.

1 answer

✓ Accepted answer

Your script never reaches the while loop at the bottom. This can be fixed by invoking a function to update the GUI, instead of using a while loop. Script:

local Player = script.Parent.Parent.Parent.Parent
local Character = Player.Character

local Thirst = 100
local Hunger = 100

local function updateGui()
	script.Parent.frameThirst.statThirst.Size = UDim2.new(Thirst*0.01, 0, 1, 0)
	script.Parent.frameHunger.statHunger.Size = UDim2.new(Hunger*0.01, 0, 1, 0)
	script.Parent.frameHealth.statHealth.Size = UDim2.new(Character.Humanoid.Health*0.01, 0, 1, 0)
end

while true do
	Thirst = Thirst -1
	Hunger = Hunger -1
	updateGui()
	wait(3)
end

1 comment

0

Thank you. I feel so stupid now!

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