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?
01 | Player = script.Parent.Parent.Parent.Parent |
02 | Character = Player.Character |
03 |
04 | Thirst = 100 |
05 | Hunger = 100 |
06 |
07 | while true do |
08 | script.Parent.frameThirst.statThirst.Size = UDim 2. new(Thirst* 0.01 , 0 , 1 , 0 ) |
09 | script.Parent.frameHunger.statHunger.Size = UDim 2. new(Hunger* 0.01 , 0 , 1 , 0 ) |
10 | script.Parent.frameHealth.statHealth.Size = UDim 2. new(Character.Humanoid.Health* 0.01 , 0 , 1 , 0 ) |
11 | wait() |
12 | end |
13 |
14 | while true do |
15 | Thirst = Thirst - 1 |
16 | Hunger = Hunger - 1 |
17 | wait( 3 ) |
18 | end |
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:
01 | local Player = script.Parent.Parent.Parent.Parent |
02 | local Character = Player.Character |
03 |
04 | local Thirst = 100 |
05 | local Hunger = 100 |
06 |
07 | local function updateGui() |
08 | script.Parent.frameThirst.statThirst.Size = UDim 2. new(Thirst* 0.01 , 0 , 1 , 0 ) |
09 | script.Parent.frameHunger.statHunger.Size = UDim 2. new(Hunger* 0.01 , 0 , 1 , 0 ) |
10 | script.Parent.frameHealth.statHealth.Size = UDim 2. new(Character.Humanoid.Health* 0.01 , 0 , 1 , 0 ) |
11 | end |
12 |
13 | while true do |
14 | Thirst = Thirst - 1 |
15 | Hunger = Hunger - 1 |
16 | updateGui() |
17 | wait( 3 ) |
18 | end |