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 5 years ago

LocalScript

local LocalPlayer = game.Players.LocalPlayer
local Assault_Rifle_Ammo = LocalPlayer.Gun_Folder.Ammo_Folder.Assault_Rifle_Ammo.Value
local Current_Ammo = LocalPlayer.Character:FindFirstChild("G36").Configuration.Ammo.Value

local Max_Ammo = 30
local Amount_Needed = Max_Ammo - Current_Ammo

if Assault_Rifle_Ammo >= Amount_Needed then --(Amount_Needed is already called
    reloadAction()
    local Amount_NeededNM = tonumber(Amount_Needed)
    script.Parent.ReloadAction:FireServer(player,Amount_NeededNM)
end

Script

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

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 5 years ago
Edited 5 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:

script.Parent.ReloadAction:FireServer(Amount_NeededNM)

Hope this helps!

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

Answer this question