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

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

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

✓ Accepted answer

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!

1 comment

0

Thanks, it worked! Accepted answer.

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