Attempt to perform arithmetic (mul) on Instance and number?

Hi, I am trying to make a cash implementation system and came across this error:

Here’s my code:

game.Players.PlayerAdded:Connect(function(player)
	local stats = player:WaitForChild("Stats")
	local boost = 1
	
	local cash = stats:WaitForChild("Cash")
	local multi = stats:WaitForChild("Multiplier")
	local reb = stats:WaitForChild("Rebirth")
	local pres = stats:WaitForChild("Prestige")
	local met = stats:WaitForChild("Meteory")
	
	while wait(0.05) do
		local function checkValue(valueObject)
			local values = valueObject.Value
			return math.clamp(values, 1, math.huge)
		end
		
		local rebLog = math.log(checkValue(reb * 0.2))
		local presLog = math.log(checkValue(pres * 1.85))
		local metLog = math.log(checkValue(met * 7.5))
		
		boost = rebLog + presLog + metLog
		boost = math.abs(boost)
		if boost < 1 then
			boost = 1
		end
		print(boost)
		
		if multi.Value >= 1 then
			cash.Value += 2 * boost * 3*multi.Value
		else
			cash.Value += 2 * boost
		end
	end
end)

It’s located in ServerScriptService as a script, why do I get this error?

1 Like

What part of your script is line 17?

local rebLog = math.log(checkValue(reb * 0.2))
local presLog = math.log(checkValue(pres * 1.85))
local metLog = math.log(checkValue(met * 7.5))
local rebLog = math.log(checkValue(reb.Value * 0.2))
local presLog = math.log(checkValue(pres.Value * 1.85))
local metLog = math.log(checkValue(met.Value * 7.5))

I already did that buy it says “attempt to index number with ‘value’”

1 Like

this line : local rebLog = math.log(checkValue(reb * 0.2))

reb is an object. You cannot multiply it.
You have to do reb.Value to multiply it; however, that’ll break your checkValue function, as that expects an object.

So how can I fix it? I didn’t make this function someone did it for me and I don’t really know how to change it

Simplest way is to remove the multiplication on lines 17-19.

You can also alter the CheckValue function to expect a number, that way you can keep your multiplication.

But then the whole point of my script isn’t going to work… I need this multiplications

In that case…

Change this line in your CheckValue function:

return math.clamp(valueObject, 1, math.huge)

And do what Min said here:

You cannot multiply an Instance, therefore you must use the number value that Instance has instead.

1 Like