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

Why am i getting this error? attempt to perform arithmetic on local 'cash' (a userdata value)

im getting this error with this code: 12:18:21.567 - Workspace.Script:3: attempt to perform arithmetic on local 'cash' (a userdata value) code:

game.ReplicatedStorage.StatChange.OnServerEvent:Connect(function(plr, cash)
	local val = plr.leaderstats.Cash
	val.Value = val.Value + cash
end)

any help would be appreciated!

1 answer

Your error is telling you that you are attempting to do 'math' on a userdata. So, the value Cash you are passing must not be a number, I would hazard a guess at saying you may have passed a NumberValue/IntegerValue as cash so try making line 3 be:

val.Value = val.Value + cash.Value

If this does not work, please try to use print(typeof(cash)) to see what you're actually passing.


  • Edit

From your comment, you are using FireServer() where you are passing game.Players.LocalPlayer, 25000 which is incorrect. Every time a local script makes a request to the server through a remote, they automatically send the client as an argument so all you need to send is the money amount.

FireServer(25000), on the server script your first argument is Player, second is the money.

2 comments

0

im passing RE:FireServer(game.Players.LocalPlayer, 25000) and it says both of them are instances

0

If RE:FireServer is from a local script TO a script, then do not pass game.Players.LocalPlayer because player is automatically sent as the first argument. I updated my answer

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