I've written the following code and am having trouble with two if statements (lines 9-14 and lines 16-21). Once hungerValue.Value == (either 50 or 20), the msg.Text does not appear anymore during that play-test.

I need to know how to have the code always be checking the hungerValue.Value, even after the statement has fired.

local hungerArray = {"I'm getting hungry.", "I'm nearly starving."}
local msg = Instance.new("Message", game.Workspace)

while wait(hungerDecrease) do
	if hungerValue.Value - 1 >= 0 then
		hungerValue.Value = hungerValue.Value - 1
	end
	
	if 
		hungerValue.Value == 50 then
		msg.Text = hungerArray[1]
		wait(5)
		msg:Remove()
	end

	if
		hungerValue.Value == 20 then
		msg.Text = hungerArray[2]
		wait(5)
		msg:Remove()
	end
end

6 comments

0

dont use wait as a condition in a while loop

0

also you could try to connect a event 

0

also :Remove() and the parent parameter of Instance.new() is decaperated, instead use :Destroy() and set the parent last

0

Not sure if I understand the problem right, but I'm pretty sure you need to move line 02 into the if statements themselves, otherwise msg will be removed and not recreated later...also, wait() is fine as a condition, it does NOT negatively affect readability like some users (literally only on this website alone) seem to believe

0

And the Message instance is deprecated. Try switching to a GUI

0

Thanks for the info, guys.