Argument 1 missing or nil?

Hello , so i’m trying to make kicker gui that allows you to kick a person out of the room.
I’ve been getting an error “Argument 1 missing or nil”. I have no idea how to fix it because the argument 1 exist. Also , im using 2 remoteevent (client & server).
Any help would be really appreciated!

  21:06:51.787 - Argument 1 missing or nil
21:06:51.788 - Stack Begin
21:06:51.788 - Script 'Workspace.TheFuzi.LocalScript', Line 45
21:06:51.788 - Stack End

Error is in the script below.

Client:

game.ReplicatedStorage.KickEventOnClient.OnClientEvent:Connect(function(kicker,name,id)
	if game.MarketplaceService:UserOwnsGamePassAsync(game.Players:GetPlayerByUserId(id).UserId,5754086) then -- error is here
	canenter = false
	plr.PlayerGui.playerList.note.Visible = true
	plr.PlayerGui.playerList.note.text.Text = "You have been kicked out of the theater by " .. kicker.Name .. ". Please wait 15 seconds to enter the theater."
	local s = Instance.new('Sound')
	s.SoundId = "rbxassetid://261082034"
	s.Parent = plr.Character.Head
	wait(0.05)
	plr.Character.Head.notif:Play()
	wait(2)
	plr.Character.Head.notif:Play()
	wait(12.95)
	canenter = true
	end
end)

Client2:

if game.MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId,5754086) then
	script.Parent.button.Visible = true
end

local open = false
script.Parent.button.MouseButton1Click:Connect(function()
	if open == false then
		open = true
		script.Parent.Frame.Visible = true
	else
		script.Parent.Frame.Visible = false
		open = false
	end
end)
script.Parent.note.TextButton.MouseButton1Click:Connect(function()
	script.Parent.note.Visible = false
end)

script.Parent.Frame.button.MouseButton1Click:Connect(function()
	if game.MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId,5754086) then
		if game.Players:FindFirstChild(script.Parent.Frame.name.Text) then
			script.Parent.Frame.Visible = false
			script.Parent.note.Visible = false
			wait(0.1)
			game.ReplicatedStorage.KickEvent:FireServer(script.Parent.Frame.name.Text,script.Parent.Frame.name)
		end
	end
end)

Server:

local timer = 180
game.ReplicatedStorage.KickEvent.OnServerEvent:Connect(function(player,who,whotext)
	if workspace:FindFirstChild(who) then
		if game.Players:FindFirstChild(who) then
			workspace[who].HumanoidRootPart.CFrame =  workspace.TeleportOutCFrame.CFrame * CFrame.new(0,3,0)
			game.ReplicatedStorage.KickEventOnClient:FireClient(game.Players:FindFirstChild(who),game.Players:FindFirstChild(who).Name,game.Players:FindFirstChild(who).UserId)
		end
	end
end)
9 Likes

What line is it erroring on?

4 Likes

2 , first script.

2 Likes

Ahh, missed that comment there.

It probably wont fix your error but why are you doing

game.Players:GetPlayerByUserId(id).UserId

Instead of just feeding it id in the first place?

2 Likes

I tried fixing it by doing that.

2 Likes

I can’t see why this wouldn’t be working.

Try swapping out :UserOwnsGamePassAsync with MarketplaceService | Documentation - Roblox Creator Hub

User owns gamepass would be preferred over that, but :woman_shrugging:

2 Likes

Wait, reading further in the wiki article, that doesn’t work anymore.

MB

4 Likes

I think I see the problem after skimming through your code.

When you fire to the server, the first argument is 'script.Parent.Frame.name.Text' and the second one is script.Parent.Frame.name. However, in the server script, you have them reversed as the who parameter is referring to the script.Parent.Frame.name.Text

Try swapping the parameters in the KickEvent.OnServerEvent to (player, whotext, who)

I have no clue how your game works and I might be completely wrong, it would help if you were able to provide a place.

3 Likes

I’m getting the same error.

2 Likes

I also noticed something else.

In the error you provided, it states it errored in Workspace.TheFuzi.LocalScript and you shouldn’t be using LocalScripts in workspace as there is no way for you to get the LocalPlayer through them since it is on the server.

Instead, move it to a Client folder such as StarterGui or StarterPlayerScripts and see if that fixes things.

1 Like

Not to get off topic, but placing a LocalScript in StarterCharacterScripts places the script into your character, which looks like it might be the case here as the full path is “Workspace.TheFuzi.LocalScript”.

1 Like

When i placed it into the “StarterGui.playerList” or “StarterPlayer.StarterPlayerScripts” it gave me the same error.

1 Like

Are you able to provide a place with the files?

1 Like

You’ve passed three arguments to FireClient:

game.ReplicatedStorage.KickEventOnClient:FireClient(game.Players:FindFirstChild(who),game.Players:FindFirstChild(who).Name,game.Players:FindFirstChild(who).UserId)

And your OnClientEvent handler takes three:

game.ReplicatedStorage.KickEventOnClient.OnClientEvent:Connect(function(kicker,name,id)

But the first argument to FireClient is the player that should receive the event, and that argument is not passed to OnClientEvent.

So your OnClientEvent handler only receives two arguments, so the third one, id, is nil, causing an error at game.Players:GetPlayerByUserId(id).

14 Likes

Also, might I recommend using the server to double check if the player owns the gamepass.

5 Likes

Ah i see. You tried sending 2 arguments which server has 3. Try fixing that. Also, I recommend reading this article: https://education.roblox.com/en-us/resources/multiple-parameters-and-arguments---code-fundamentals to get a better understanding of arguments.

3 Likes