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?

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

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:

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
0
Thank you. I feel so stupid now! MisaMiner 50 — 10y
Ad

Answer this question