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)
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
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
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
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