Attempt to perform arithmetic (add) on number and Instance.... Error

Hey there,
I wanted to make a button that increases your Stats Value but im just getting the error in the topic.

LocalScript:

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	local increment = 1
	game.ReplicatedStorage.IncrementDam:InvokeServer(plr,increment)
end)

ServerScript:

game.ReplicatedStorage:WaitForChild("IncrementDam").OnServerInvoke = function(player,increment)	
	player.Stats.DamageMul.Value += increment
end

Does anyone know the issue?

can you show the directory of the stats folder and stuff

The Stats Folder gets created like a leaderstat in the local player.
Unbenannt

try adding some debug code to see if the problem has to do with the value object or smth

game.ReplicatedStorage:WaitForChild("IncrementDam").OnServerInvoke = function(player,increment)	
	print(player.Stats.DamageMul)
    print(player.Stats.DamageMul.Value)
   print(increment)
    player.Stats.DamageMul.Value += increment
end

ok your problem seems to be that the player is being passed through the remote function as “increment” rather than the local variable increment

1 Like

i believe that player is already passed through the function from the client side invokation, so instead of doing invokeServer(plr, increment) just do invokeServer(increment)

so the problem is that since you sent the plr through the invoke, there is actually 3 arguments being passed: player, plr, and increment. when you set up the onServerInvoke you named the first 2 of them player and increment, but they corrosponded to player and plr, and incremenet was left unused

1 Like