Hello.
To access information in a table you do:
TableName[Information] It will return false if the information is not in the table, if it is, it will return its value. Here is a simple whitelist script.
local AllowedPlayers = {
["PlayerName1"] = true,
["PlayerName2"] = true,
["PlayerName3"] = true,
["PlayerName4"] = true
}
game.Players.PlayerAdded:Connect(function(player)
if not AllowedPlayers[player.Name] then
player:Kick("You are not allowed to join this game!")
end
end)
game.Players.PlayerAdded:Connect(function(player)
if AllowedPlayers[player.Name] then
end
end)
Anyways, you can do this in multiple ways. Here's your fixed code:
local Players = {"JakyeRU", "ABC", "DDCDS"}
game.Players.PlayerAdded:Connect(function(player)
for _, v in pairs(Players) do
if player.Name == v then
end
end
end)
What was wrong with your code?
You checked (if PlayerName == Table) which is not correct.
The v will become the element in the table. The for loop will repeat 3 times. v will be JakyeRU, ABC, and DDCDS. That's why you do (if playerName == v) or (if v == PlayerName). You compare 2 strings.
2 comments
try plr.Name instead of v.Name
Needs to be
if plr.Name == v