Sorry if the title is confusing; I'll explain better here.
In the below code, the program is waiting 10 seconds, subtracting from an IntValue (hungerValue.Value), then checking that IntValue. If the value == 60, 40, or 20, it displays one of three messages from an array.
I also want have this hungerValue decrease when the player jumps, but the code only checks for the hungerValue.Value after every 'wait(10).' Meaning, the messages only appear if the hungerValue ticks down. If a player 'jumps' his/her hungerValue down to 60,40, or 20, the gui doesn't appear.
So, my underlying question is: how can I check those if statements at every moment, so that if the player 'jumps' his/her hungerValue down to 60, 40, or 20, the gui appears.
while wait(10) do if hungerValue.Value - 1 >= 0 then hungerValue.Value = hungerValue.Value - 1 end if hungerValue.Value == 60 then HungerFrame.TextLabel.Text = hungerStrings[1] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end if hungerValue.Value == 40 then HungerFrame.TextLabel.Text = hungerStrings[2] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end if hungerValue.Value == 20 then HungerFrame.TextLabel.Text = hungerStrings[3] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end
Any help or hints in the right direction would be greatly appreciated!
two ways you can check if the value changed:
hungerValue.Value.Changed:Connect(function() if hungerValue.Value == 60 then HungerFrame.TextLabel.Text = hungerStrings[1] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end if hungerValue.Value == 40 then HungerFrame.TextLabel.Text = hungerStrings[2] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end if hungerValue.Value == 20 then HungerFrame.TextLabel.Text = hungerStrings[3] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end end)
or you can constantly check it by using spawn functions they are code that runs but the script keeps them going while the rest of the script continues
spawn(function() while true do wait() if hungerValue.Value == 60 then HungerFrame.TextLabel.Text = hungerStrings[1] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end if hungerValue.Value == 40 then HungerFrame.TextLabel.Text = hungerStrings[2] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end if hungerValue.Value == 20 then HungerFrame.TextLabel.Text = hungerStrings[3] HungerFrame.Visible = true wait(5) HungerFrame.Visible = false end end end)