Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

0
im passing RE:FireServer(game.Players.LocalPlayer, 25000) and it says both of them are instances testing34545 12 — 5y
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 alphawolvess 1784 — 5y
Ad

Answer this question