Attempt to perform arithmetic (add) on Instance and number

Basically, I have a food item, that when eaten, it adds +7 to your hunger value. (if hunger = 0 you die)

Script:

local Tool = script.Parent;
enabled = true;
function onActivated()
	if not enabled  then
		return;
	end
	enabled = false;
	Tool.GripForward = Vector3.new(.995, -.0995, -8);
	Tool.GripPos = Vector3.new(-1.5, -0.9, 0.5);
	Tool.GripRight = Vector3.new(-1, 0, 0);
	Tool.GripUp = Vector3.new(0, 1, 0);
	wait(.8);
	local h = Tool.Parent:FindFirstChild("Humanoid");
	local plr = game.Players:GetPlayerFromCharacter(h.Parent);
	if (plr ~= nil) then
		if (100 > plr.Hunger + 7) then -- where error occurs
			plr.Hunger = plr.Hunger + 7
		else	
			plr.Hunger = 100
		end
	end
	Tool.GripForward = Vector3.new(0, 0, -1);
	Tool.GripPos = Vector3.new(0, 0, 0.5);
	Tool.GripRight = Vector3.new(1, 0, 0);
	Tool.GripUp = Vector3.new(0,1,0);
	enabled = true;
	Tool:Destroy()
end
function onEquipped()
	Tool.Handle.OpenSound:play();
end
script.Parent.Activated:connect(onActivated);
script.Parent.Equipped:connect(onEquipped);

However, I get this error: attempt to perform arithmetic (add) on Instance and number

At line 18, I have marked it in my script.

I fixed the main issue, by using tonumber(), however the hunger value is not going up.

Could you explain what “hunger” instance is inside the Player?

It’s a regular IntValue starting at 100, which decreases by 5 every 5 seconds.

To use the value of IntValue in any kind of arithmetic actions, you need to interact with it’s Value property. So it would be: IntValue.Value.

1 Like

Thanks, I seem to always overlook the value property when scripting, thanks for reminding me

1 Like

C in connect should be uppercase, like this: :Connect

I’ll change it, but just wondering, does it cause any issues if I use a lowercase C? Or is it just deprecated

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.