Hey, I’m trying to code a game ban, by ID that on player join, the script will check if the user’s ID is equal to a user ID I set. How would I do this? This is my current script:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if player.UserId == 1035365524 then
player:Kick("You are banned from this game! Reason: Exploiting.")
else
print("This user is OK!")
end
end)
Anything I messed up in my script that I should change, please tell me as I’m horrible at this.
Your script will work. You can also do something like:
local banList = {
[55549140] = "Being a noob";
[1035365524] = "Exploiting";
}
Players.PlayerAdded:Connect(function(player)
for userId, reason in pairs (banList) do
if player.userId == userId then
player:Kick("You have been banned from this game for" .. reason)
end
end
end
local Players = game:GetService("Players")
local UserIds = {12345, 12345, 54321}
Players.PlayerAdded:Connect(function(Player)
for _, UserId in UserIds do
if (Player.UserId == UserId) then
Player:Kick("You are banned.")
end
end
end