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

attempt to perform arithmetic on local 'Amount_NeededNM' (a userdata value)?

Asked by 6 years ago

LocalScript

01local LocalPlayer = game.Players.LocalPlayer
02local Assault_Rifle_Ammo = LocalPlayer.Gun_Folder.Ammo_Folder.Assault_Rifle_Ammo.Value
03local Current_Ammo = LocalPlayer.Character:FindFirstChild("G36").Configuration.Ammo.Value
04 
05local Max_Ammo = 30
06local Amount_Needed = Max_Ammo - Current_Ammo
07 
08if Assault_Rifle_Ammo >= Amount_Needed then --(Amount_Needed is already called
09    reloadAction()
10    local Amount_NeededNM = tonumber(Amount_Needed)
11    script.Parent.ReloadAction:FireServer(player,Amount_NeededNM)
12end

Script

1script.Parent.ReloadAction.OnServerEvent:Connect(function(player,Amount_NeededNM)
2    local playerammoV = player.Gun_Folder.Ammo_Folder.Assault_Rifle_Ammo.Value
3    playerammoV = playerammoV - Amount_NeededNM
4end)

Error attempt to perform arithmetic on local 'Amount_NeededNM' (a userdata value)

I've attempted this; -Without using tonumber (same error) -Using .Value (didn't work since there isn't a .Value to a variable)

Every article I've read regarding something similar to this doesn't output the error stating "arithmetic on local", and "a userdata value". So I thought I'd resort here, doing everything I could think of, I don't have a clue as to what I need to do. watch it be just smth so simple to avoid

1 answer

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

Hello ImperiumDomini2,

The issue is that FireServer doesn't require a player parameter to be placed within the call. That being said, it's trying to perform arithmetic on the player variable you passed.

I recommend simply calling it as:

1script.Parent.ReloadAction:FireServer(Amount_NeededNM)

Hope this helps!

0
Thanks, it worked! Accepted answer. ImperiumDomini2 39 — 6y
Ad

Answer this question