Hello, so this whitelist script I made only checks the first person on the list, but I want the list to include everyone, any help?
local whitelist = {
"664880421",
"2513627682",
}
game.Players.PlayerAdded:Connect(function(player)
for i,v in pairs(whitelist) do
if v ~= player.UserId then
player:Kick("You're not allowed here.")
end
end
end)
Yeah, I copied them directly from the profiles. Yet it still doesn’t work, try using ROBLOX’s user id or something first and then yours and it won’t let you in.
local whitelist = {
664880421,
2513627682,
}
game.Players.PlayerAdded:Connect(function(player)
for i,v in pairs(whitelist) do
if v ~= player.UserId then
player:Kick("You're not allowed here.")
end
end
end)
What’s happening is that strings are not the same as integers.
The player cannot be equal to both user Id’s, this is the issue.
You can try this:
local whitelist = {
"664880421",
"2513627682",
}
game.Players.PlayerAdded:Connect(function(player)
local found = false
for i,v in pairs(whitelist) do
if v == player.UserId then
found = true
end
end
if not found then
player:Kick("You're not allowed here.")
end
end)
Your kick function is being run every time the userId does not match. This means it will check the first element. If the first element does not equal their userId, it will kick them. You need to do a final check after running through the entire table.
local whitelist = {
"664880421",
"2513627682",
}
game.Players.PlayerAdded:Connect(function(player)
local whitelisted = false
for i,v in pairs(whitelist) do
if v == player.UserId then
whitelisted = true
break;
end
end
if not whitelisted then
player:Kick("You're not allowed here.")
end
end)
local whitelist = {
664880421,
2513627682,
}
game.Players.PlayerAdded:Connect(function(player)
local whitelisted = false
for i,v in pairs(whitelist) do
if v == player.UserId then
whitelisted = true
break;
end
end
if not whitelisted then
player:Kick("You're not allowed here.")
end
end)
local players = game:GetService("Players")
local whitelist = {
664880421,
2513627682,
}
players.PlayerAdded:Connect(function(player)
if not table.find(whitelist, player.UserId) then
player:Kick("Not whitelisted")
end
end)
What this will do is check if someone who joins the game has a userid that is in the table. If they don’t have a userid that is in the table, they will get kicked from the game.
local whitelist = {664880421,2513627682}
game.Players.PlayerAdded:Connect(function(player)
if not whitelist[player.UserId] then
player:Kick("You're not allowed to join this game.")
end
-- do stuff down here for if they are allowed to join (in the whitelist)
end)