Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't the third value in my hungerbar script get checked?

In my survival game, I have a hunger bar that works 67%. The rest is when your hunger is less than 65. If your hunger is 65 and up, after eating the food your hunger will be 100. If It is 100, it will stay 100, and if it's below 65, it's supposed to add 35 to it... but it doesn't.

The problematic part is that the hunger's value is always checked properly, but when it comes down to your hunger being less than 65, it... doesn't check?

Here's the code for it: (Script inside a tool inside starterpack)

local Tool = script.Parent
local player = Tool.Parent.Parent
local huunger = game.StarterGui.Status.Hunger
local hunger = huunger:WaitForChild("Change")
local MaxHunger = 100
local NewHunger = 0.05
enabled = true




function onActivated()
	if not enabled  then
		return
	end

	enabled = false


	Tool.Handle.DrinkSound:Play()

	wait(.8)
	
	local h = player
	
	enabled = true

			if h.stats.Hunger.Value == 100 then
		h.stats.Hunger.Value = 99
		print("1")
		if h.stats.Hunger.Value < 100 then
			h.stats.Hunger.Value = 99
			Tool:Destroy()
			print("2")
		end
	end

	if h.stats.Hunger.Value < 64 then
		h.stats.Hunger.Value -= 65
		Tool:Destroy()
		end
	hunger:TweenSize(UDim2.new(player:WaitForChild("stats").Hunger.Value / 0,0,0,0), "Out", "Quint", 0.8, true)
end

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

2 answers

on line 31 try adding "and >= 64" 30 is less than 64 AND 100, so it could cause problems

rokkufera already answered this, I just changed your if/else statement for you.

31	        if h.stats.Hunger.Value < 100 and >= 65 then
32	            h.stats.Hunger.Value = 99
33	            Tool:Destroy()
34	            print("2")
35	        end

This discussion is preserved as it was. New answers, comments, and votes are closed.