Hello. I’m trying to achieve a system that checks if a player is a certain user by checking their name on playerAdded, and kicking them if they are not from the table of player string names.
It is kicking me, even though I am on the table, why is this happening?
I’ve tried switching to userIds, not working? I do not know why.
local playerNames = {"user1","user2","user3"}
game.Players.PlayerAdded:Connect(function(plr)
wait(5)
if table.find(playerNames,plr.Name) then
print(plr.Name .. " is a tester or is owner.")
else
wait(1)
print(plr.Name .. " is not tester, kicking...")
plr:Kick("You are not a tester; you do not have access to the game.")
end
end)
It isn’t good a Good idea to be using their Names as they can easily change them and gain access to the game again Lose access to the game, use their UserId which is a permanent thing assigned to their account.
-- try this
local Testers = {
"User1",
"User2",
"User3"
}
game:GetService("Players").PlayerAdded:Connect(function(player)
for i, tester in pairs(Testers) do
if tester == player.Name then
print("Player is a tester or owner")
else
player:Kick("Not a tester.")
end
end
end)
local Testers = {
paste your id here,
paste your id here
}
game:GetService("Players").PlayerAdded:Connect(function(player)
task.wait(5)
for i, tester in pairs(Testers) do
if tester == player.UserId then
print("Player is a tester or owner")
else
player:Kick("Not a tester.")
end
end
end)
oh, i was like i saw - i corrected. Yes, it is, here the code
local Testers = {
paste your id here,
paste your id here
}
game:GetService("Players").PlayerAdded:Connect(function(player)
task.wait(5)
if table.Find(Testers, player.UserId) then
print("Player is a tester")
else
player:Kick("Not a tester.")
end
end)
You dont need to add a wait to it lol. This should work.
local Players = game:GetService("Players")
local playerNamesTable = {"user1","user2","user3"}
Players.PlayerAdded:Connect(function(Player)
if not table.find(playerNamesTable, Player.Name) then
Player:Kick("You are not a tester; you do not have access to the game.")
end
end)
Actually nvm, this system doesn’t appear to work, it would probably be best if you iterated through the table as for some reason, it returns nil instead of giving you the index.
I recommend using collaboration and allowing your testers to play while keeping it private because otherwise if a random players try’s to play and they get kicked they will not want to return when the game is out.