Im getting kicked when I'm whitelisted

Hey Developers,
I am making a feature in my game, I am going to get some beta testers for it, so I made a whitelist system. I have entered my Roblox Username in there, but I am getting kicked.
Here is my script:

local PlayerService = game:GetService('Players')
local Allowed = {'JamesRBLX', 'Little_Joes', 'EcoCrashed', 'Thecrazyman97', 'triggerstickz'}

PlayerService.PlayerAdded:Connect(function(Player)
	for _, Plr in pairs(Allowed) do
		if Plr == Player.Name then
			Player:Kick("Sorry, the game isn't public yet. The release date is the 19th April. Please do not dislike this game.")
		end
	end
end)

Thanks for help!

3 Likes

You can just do

local PlayerService = game:GetService('Players')
local Allowed = {'JamesRBLX', 'Little_Joes', 'EcoCrashed', 'Thecrazyman97', 'triggerstickz'}

PlayerService.PlayerAdded:Connect(function(Player)
		if not table.find(Allowed, Player.Name) then
			Player:Kick("Sorry, the game isn't public yet. The release date is the 19th April. Please do not dislike this game.")
		end
end)

It will try to find you in the table, and return false (not) if it doesn’t find you.

What this code is doing is making a blacklist, rather than a whitelist. You can try out this code:

local found = false
for _, plr in pairs(Allowed)  do
    if plr == Player.Name then
        found = true
        break
    end
end

if not found then
    -- kick the player
end

This should be in the PlayerAdded event

3 Likes

Yeah, it quite literally is a blacklist.

1 Like

You should use player IDs instead of names. If they change their user name which I doubt they will do but they might they can’t join and the have to spend 1000 extra robux on a new username.

2 Likes

I was about to write a reply to save UserIds instead of Player names XD

2 Likes

By the way, if you are able to, you can set play access via the Game Access Permissions window, assuming this is a personal game and not a group game. That’ll disable the play button altogether for people you don’t whitelist. You then don’t need to worry about a whitelist script or asking people not to dislike an unreleased game (which people will and ignore your plea).