Script not kicking player

I am trying to make a ban script but I keep getting an error when trying to kick a player.

Script:
local Players = game:GetService(“Players”)

local Market = game:GetService(“MarketplaceService”)

local info = Market:GetProductInfo(game.PlaceId)

local PbanCheck = game.ReplicatedStorage:WaitForChild(“PbanCheck”)

local Pban = {
“”
}

local Commands = {}

Players.PlayerAdded:Connect(function(Player)
if table.find(Pban, Player.Name) then
PbanCheck:FireClient(Player)
else
print(“Not Banned”)
end
end)

function Commands.ban(Playertoban)
Playertoban:kick(“Ban”)
if not table.find(Pban, Playertoban) then
table.insert(Pban, Playertoban)
print("Data Added, "…Playertoban)
end
end

game.Players.PlayerAdded:Connect(function(Playerone)
Playerone.Chatted:Connect(function(Message)
if Message == “!ban” then
Commands.ban(“bodiedog28”)
end
end)
end)

Firstly what is the error. Secondly the args aren’t split up correctly and one error could mess up the entire script. Thirdly do this format:

```lua
--code
--```

Remove the --. :slight_smile:

Error:
ServerScriptService.Script:24: attempt to call a nil value
Stack begin
Script ‘ServerScriptService.Script’, Line 24 function ban
Script ‘ServerScriptService’, Line 34
Stack end

Make the k a cap letter. I really have no clue why this isn’t working.
Are you using a script or a local script btw?

Script script script script script (30)

Changing it to upper case didn’t work

Is the player inside of the game? If not then its going to be nil. :slight_smile:

The player is inside the game(30 30 30)

PlayerToBan is a string, I believe. :Kick is not a valid function of that string. Try this:

function Commands.ban(Playertoban)
	Playertoban = game.Players:FindFirstChild(Playertoban)
	if not Playertoban or not Playertoban:IsA("Player") then
		return
	end
	Playertoban:Kick("Ban")
	if not table.find(Pban, Playertoban.Name) then
		table.insert(Pban, Playertoban.Name)
		print("Data Added, "...Playertoban.Name)
	end
end

Ok I’ll try it(30 30 30 30 30)

Dang it I was just going to say this. I should really check scripts before I say something.
Yes you can’t kick the plr with only the string, you need the plr object

1 Like

The string(s) used ..., which is used for a function argument for (infinite?) arguments but .. is used to concatenate or combine strings.

function Commands.ban(Playertoban)
	Playertoban = game.Players:FindFirstChild(Playertoban)
	if not Playertoban or not Playertoban:IsA("Player") then
		return
	end
	Playertoban:Kick("Ban")
	if not table.find(Pban, Playertoban.Name) then
		table.insert(Pban, Playertoban.Name)
		print("Data Added, "..Playertoban.Name)
	end
end

Thank you for all your help, this post is now solved!