"Argument 1 missing or nil" when calling remote events with more than 1 argument(plr, ...)

On line 5(... if player:WaitForChild("Data").Items:FindFirstChild(item) then ...) it throws an error which is the title; I’ve tried multiple ways of this, and rechecked that the player argument and the item argument were not nil.
I think that I would have to silence the 1st argument with nil(...Items:FindFirstChild(nil, item)) which is in the function, but, as soon as i did that it gave me the same error.
Anyone knows how to fix that?
Note(s):
This is a server script;
Remote was called from StarterPlayerScripts
Here’s a script that i have right now:

local rs = game:GetService("ReplicatedStorage")

rs.pickupitem.OnServerEvent:Connect(function(player, item)
	if player:WaitForChild("Data").Items:FindFirstChild(item) then
		print(player.." already has the item")
	else
		local thingthatadded = Instance.new("IntValue")
		thingthatadded.Parent = player:WaitForChild("Data").Items
		thingthatadded.Name = "TestItem"
		if thingthatadded.Value == 0 then
			thingthatadded.Value = 1
		elseif thingthatadded.Value > 0 then
			thingthatadded.Value = thingthatadded.Value + 1
		end
	end
end)

tl;dr i need it so that i wouldn’t get the error anymore

If you need more details, take a look at the following algorithm.


Its messy. I know.

1 Like

Are you firing server with the player as an argument? If so then it should be left empty since the server already gets the player from whatever client the remote was fired from. Otherwise I have no idea

Are you firing server with the player as an argument?

Do you mean this?

rs.pickupitem.OnServerEvent:Connect(function(item)

No I mean in the client where you do :FireServer()

I currently have this in the localscript, with the first argument being item, then the player.

script.pickupitem.OnClientEvent:Connect(function(item, player)
	rs.pickupitem:FireServer(player, item)
	local thingtoget = rs.CraftingMaterials:FindFirstChild(item)
	local thingtopass = thingtoget:Clone()
	thingtopass.Parent = game.Players.LocalPlayer.PlayerGui.ScreenGui.Menus.CraftingMaterials
end)

You mean that, i should remove the player argument and only leave the item?

First of all since it is a local script you get the player just by doing game.Players.LocalPlayer so no need to pass that in, second I was correct, let me explain the scope of this.

When you call :FireServer from a specific client the server can already tell which client fired it so there wont even be a need for you to send that in so you end up having rs.pickupitem:FireServer(item)

1 Like
rs.pickupitem.OnServerEvent:Connect(function(item)

Needs to be:

rs.pickupitem.OnServerEvent:Connect(function(player, item)

When the client fires the server via a call to the instance method “FireServer()” on a RemoteEvent instance the player object belonging to that client is automatically passed as an argument to the FireServer() call and is subsequently,received by the same RemoteEvent’s corresponding OnServerEvent event.