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

Thirst/Hunger bar not changing?

Asked by 10 years ago

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?

01Player = script.Parent.Parent.Parent.Parent
02Character = Player.Character
03 
04Thirst = 100
05Hunger = 100
06 
07while true do
08    script.Parent.frameThirst.statThirst.Size = UDim2.new(Thirst*0.01, 0, 1, 0)
09    script.Parent.frameHunger.statHunger.Size = UDim2.new(Hunger*0.01, 0, 1, 0)
10    script.Parent.frameHealth.statHealth.Size = UDim2.new(Character.Humanoid.Health*0.01, 0, 1, 0)
11    wait()
12end
13 
14while true do
15    Thirst = Thirst -1
16    Hunger = Hunger -1
17    wait(3)
18end
0
UPDATE: I did find that the bars are working. Only thing is, the values will not change. MisaMiner 50 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

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:

01local Player = script.Parent.Parent.Parent.Parent
02local Character = Player.Character
03 
04local Thirst = 100
05local Hunger = 100
06 
07local function updateGui()
08    script.Parent.frameThirst.statThirst.Size = UDim2.new(Thirst*0.01, 0, 1, 0)
09    script.Parent.frameHunger.statHunger.Size = UDim2.new(Hunger*0.01, 0, 1, 0)
10    script.Parent.frameHealth.statHealth.Size = UDim2.new(Character.Humanoid.Health*0.01, 0, 1, 0)
11end
12 
13while true do
14    Thirst = Thirst -1
15    Hunger = Hunger -1
16    updateGui()
17    wait(3)
18end
0
Thank you. I feel so stupid now! MisaMiner 50 — 10y
Ad

Answer this question