Attempt to perform arithmetic (add) on number and Instance

Hello. I’m getting the error *attempt to perform arithmetic (add) on number and Instance * coming from line 3 of this server script

The Code

game.ReplicatedStorage.Event.OnServerEvent:Connect(function(Player, Amount)
	
	Player.leaderstats.Coins.Value += Amount
end)

Can you print your Amount variable?

1 Like

Could you show us your client-sided code? I presume that you have accidentally written:

-[[Path.to.RemoteEvent]]:FireServer(Player, Amount)
1 Like
local Car = script.Parent.Parent.Object.Value

local Player = game:GetService("Players").LocalPlayer

local ReplicatedStorage = game:GetService("ReplicatedStorage")

Car:GetPropertyChangedSignal("Name"):Connect(function()
	
if Car.Name == "Destroyed" and Car.Destroyed.Value == false then
		
		local Amount = 100
		
		local Event = ReplicatedStorage.Event
		
		Event:FireServer(Player, Amount)

		Car.Destroyed.Value = true
	else
		return
			
   end	
end)

I assumed correctly.

RemoteEvent.OnServerEvent listeners automatically receive the Player instance of the client that called RemoteEvent:FireServer. Additional arguments follow:

local function OnServerEvent(Player, ...)

With the additional Player instance passed, Amount gets occupied by the instance.

See “Remote Functions and Events” for a refresher.

TL;DR: Remove your first argument to FireServer.

1 Like

You dont need to put player as the first parameter in fireserver, because upon .OnServerEvent firing the player is the first parameter recieved

Client

RemoteEvent:FireServer(Amount)

Server

RemoteEvent.OnServerEvent:Connect(function(Player, Amount) -- PLayer is first parameter by default
end)
1 Like