Argument 1 is missing or nil

The textbox’s text is the user id of the player I want to ban. here is my code:

local banUserID = script.Parent.Frame.BanUserID
local id = banUserID.UserId.Text
local fd = tonumber(id)

banUserID.Ban.MouseButton1Click:Connect(function()
	local plrToBan = game:GetService("Players"):GetPlayerByUserId(fd)
	plrToBan:Kick("haha get banned")
end)
1 Like

Which line points to the error?

local plrToBan = game:GetService(“Players”):GetPlayerByUserId(fd)

The reason this is erroring is because fd is being set to the text of the TextBox, which is empty when the script starts and you don’t update the variable after the TextBox content has changed.
tonumber returns nil if there is no valid number. For example, tonumber("string") returns nil because there is no number, and that’s what’s happened in this script, fd is tonumber(""), so it’s nil.

It’s also worth mentioning that because this should be in a client script you shouldn’t be kicking in the same script, you should be using a remote event. You can read up on them here, they help bridge the gap between client and server. Bindable Events and Functions | Roblox Creator Documentation

Try something along these lines:
Client:

Button.MouseButton1Click:Connect(function()
 RemoteEvent:FireServer(Id)
end)

Server:

RemoteEvent.OnServerEvent:Connect(function(Player, Id)
local fd = tonumber(id)
local plrToBan = game:GetService("Players"):GetPlayerByUserId(fd)
plrToBan:Kick("haha get banned")
end)

Note that this is a rough example.

Hope that this could help you! :smiley:

Have you made sure the text box only contains numbers and no spaces?

Make sure fd exists and than the text has numbers for sure.

I tried your solution, it did not work. Also I know that Kick should be done in another script, its just that im testing this ban player by user id system

Yes

Character69696996969696xdxd

This is the solution that I hinted at if you were to keep everything in one script, is it what you tried? Redefining the variables after the click. It’s probably worth your time to add a couple of if statements in there as well, I’ve added an example one in there for you:

local banUserID = script.Parent.Frame.BanUserID

banUserID.Ban.MouseButton1Click:Connect(function()
	local id = banUserID.UserId.Text
	local fd = tonumber(id)
	if fd then
		local plrToBan = game:GetService("Players"):GetPlayerByUserId(fd)
		plrToBan:Kick("haha get banned")
	else
		banUserID.UserId.Text = "Please insert a valid number!"
	end
end)
1 Like

I dont know what happened, but it works now for some reason (my old script)

Edit: Nevermind, its probably because I added the variables in the function itself, thanks for the help

Your old script shouldn’t be working. Perhaps you set the text in studio and then pressed play?
Is your intent for the player to input a userid?