Argument 1 missing or nil

I am having an issue with with this error.
I don’t know what causes it and I’ve tried to search for solution, but I don’t get it.

Local script:

local gunname = script.Parent.Name
local player = game.Players.LocalPlayer
local selection = game.ReplicatedStorage.GameEvents:WaitForChild("GunSelect")

local debounce = false
script.Parent.MouseButton1Click:Connect(function(player)
	print(gunname)
	if debounce == false then
		debounce = true
	selection:FireServer(player,gunname)
	else
		
	end
end)

Server Script:

local selection = game.ReplicatedStorage.GameEvents:WaitForChild("GunSelect")
local guns = game.ReplicatedStorage:WaitForChild("Guns")

selection.OnServerEvent:Connect(function(player,gunname)
	local givengun = guns:WaitForChild(gunname)
	givengun:Clone().Parent = player.Backpack
	
end)

Apparently the error is in the Server Script, 5th line.
I would be very happy if anyone could find the solution.

1 Like
selection:FireServer(gunname)

When calling FireServer() through a RemoteEvent instance from the client side within a local script the player object pertaining to the particular client which is firing the server is automatically passed as an argument to the callback function connected to the corresponding OnServerEvent event through the same RemoteEvent instance listening from the server side within a server script, as such all we need to do is declare an additional parameter to handle this received object on the server side, as the player object is the first value received the first parameter should represent that, additional parameters are then required to handle any optional arguments passed to FireServer() when it is called.

2 Likes

What @Forummer said appears to be correct (only skimmed it), but this is also a good time to note that you should be checking what gets passed from the client to the server regardless.

selection.OnServerEvent:Connect(function(player,gunname)
    if type(gunname) == "string" and guns:FindFirstChild(gunname) then
	    local givengun = guns[gunname]
	    givengun:Clone().Parent = player.Backpack
    end
end)
1 Like

Wow, it took less than a minute to find a solution. Thanks for the help!!

Oh, I see.
Very helpful, thanks for info!