Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

attempt to perform arithmetic (add) on number and Instance ?

can someone help? i am trying to create an event that gives the player an amount of a currency when they finish a game but it errors:

  00:26:32.985 - ServerScriptService.getClout:2: attempt to perform arithmetic (add) on number and Instance
00:26:32.986 - Stack Begin
00:26:32.986 - Script 'ServerScriptService.getClout', Line 2
00:26:32.986 - Stack End

server script:

-- server
game.ReplicatedStorage.getCloutEvent.OnServerEvent:Connect(function(player, award)
	player.leaderstats.Clout.Value=player.leaderstats.Clout.Value+award
end)

on client:

-- client
local localplayer = game.Players.LocalPlayer
local score = scoreFrame.Score.Text
game.ReplicatedStorage.getCloutEvent:FireServer(localplayer,score)

1 answer

✓ Accepted answer

You do not need to send the LocalPlayer instance through a RemoteEvent. The Player that fires the RemoteEvent will automatically be sent as the first argument. The issue here is that since you send the LocalPlayer through the event, both values on the server are actually a Player instance, since the first parameter is the Player defined by the RemoteEvent's default behavior, and the 2nd is the LocalPlayer argument you sent. Therefore, you're not performing math on 'score', a number, but rather on a Player instance.

Your client side remote code should look like this after excluding the LocalPlayer argument:

game.ReplicatedStorage.getCloutEvent:FireServer(score)

Hope this explanation helped.

1 comment

0

thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.