Attempt to perform arithmetic (add) on boolean and number

Hello everyone!! I’m trying to make a food system that fires a remote event whenever a tool gets activated, and a server script checks if the name of the food is inside of the Foods table and if it is, it gets the food from the table and adds the value of HungerIncrement to the players hunger.

The problem is whenever I activate the tool, I get attempt to perform arithmetic (add) on boolean and number.

I know what the error message means and I’ve tried printing everything that errors and it prints 95; 100; 100, none of them are booleans and I don’t know where it gets the boolean from.

This is the server script. There’s a localscript located inside the tool that fires a remote whenever it gets activated, but I don’t know if that has anything to do with the error so I didn’t put it here. I’ll send it here if anyone wants more information.

(I’m also really new with dictionaries and tables so I’m sorry if the solution is obvious.)

local Foods = {
	["Carrot"] = {["Sour"] = false, ["HungerIncrement"] = 10},
	["Apple"] = {["Sour"] = false, ["HungerIncrement"] = 8},
	["Lemon"] = {["Sour"] = true, ["HungerIncrement"] = 3},
	["Orange"] = {["Sour"] = true, ["HungerIncrement"] = 6},
}

local function Activated(Player, FoodName)
	local Food = Foods[FoodName.Value]
	if Food then
		local PlayerData = Player:FindFirstChild("playerData")
		local Hunger = PlayerData:FindFirstChild("Hunger")
		
		if PlayerData and Hunger then
			print(Hunger.Value.. "; ".. Food["HungerIncrement"].. "; ".. MAX_HUNGER) -- this prints "95; 100; 100"
			if not Hunger.Value + Food["HungerIncrement"] >= MAX_HUNGER then
				Hunger.Value += Food["HungerIncrement"]
			else Hunger.Value = MAX_HUNGER end
		end
	end
end

EatEvent.OnServerEvent:Connect(Activated)

Any help is appreciated, thank you so much!

Does anyone know how to solve this?

Change not Hunger.Value + Food["HungerIncrement"] >= MAX_HUNGER to not (Hunger.Value + Food["HungerIncrement"] >= MAX_HUNGER)

Having not before Hunger.Value causes it to turn its type into a boolean before attempting to add.

1 Like

Thank you!! I don’t get the error anymore but when I try to print the value of hunger it doesn’t do anything but I think I can solve that myself.