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!
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.
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.