Whitelist script not working

Hello,
Not a long time ago i asked for help to make a script for a testing server where only a few selected players can join
i did make the script but now it will kick all the players and that’s not what i wanted so check this script out and help me out if you can.

local WhiteList = {"TurteleDJ", "GreenTxrtIe", "NotKxng"}

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		for i = 1, #WhiteList do
			if WhiteList[i] == plr.Name then
				print("Owner did join the game")
			elseif WhiteList[i] == plr.Name == false then
				plr:Kick("You are not allowed to join the game only game devs can join the game this game is in test proces")
			end
		end
	end)
end)

This is also my previous question where i asked for it to help me out.

2 Likes

I would use table.find() in this case.

Can you try this:

local WhiteList = {"TurteleDJ", "GreenTxrtIe", "NotKxng"}

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
			if table.find(WhiteList, plr.Name) then
				print("Owner did join the game")
			else
				plr:Kick("You are not allowed to join the game only game devs can join the game this game is in test proces")
			end
	end)
end)
4 Likes

Well it’s working for now i will test the scipt with an other account.

1 Like

Instead of joining with another account you can just remove your name in the table just to see if it’s working.

3 Likes

I already did it and it worked ty for your help!

2 Likes

I did made this script after it to show a UI before it kicks the player the player can only stay for 100 seconds

local ServerLockUI = game.StarterGui.ServerIsLocked
local ServerLocked = script.ServerLocked
local WhiteList = {"TurteleDJ", "GreenTxrtIe", "NotKxng"}

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		if table.find(WhiteList, plr.Name) then
			print("Owner did join the game")
		elseif ServerLocked.Value == true then
			if table.find(WhiteList, plr.Name) then
			else
				ServerLockUI.Enabled = true
				wait(100)
				plr:Kick("You are not allowed to join the game only game devs can join the game this game is in test proces")
			end
		end
	end)
end)

and now it is not working anymore bruh

1 Like

The only reason your solution worked is because you used table.find() with the whitelisted player string in the table, whilst OP used a number to index a table, returning nil.

Even then @DevTurtIe, I highly recommend using UserIds of the player, not the username to avoid conflict if the player changes their name.

2 Likes

I will try to use the id’s right now also why didn’t the previous code above this worked cause it’s kicking you again i wanted to show a UI before kicking the player.

1 Like

You should enable the Gui from the PlayerGui because player is seeing the PlayerGui whenever they join, not StarterGui. To get the PlayerGui you can do local PlayerGui = plr:WaitForChild("PlayerGui") inside the PlayerAdded event.

3 Likes

You can also se at the left i used a boolValue in the script

1 Like

so something like this

local ServerLockUI = plr:WaitForChild(“PlayerGui”)
ServerLockUI.ServerIsLocked.enabled = true|

1 Like

Connecting your script to a CharacterAdded is unecessary, since you already have the Player object. No neeed to repeat this everytime they respawn.

Try this:

local ServerLocked = script.ServerLocked
local WhiteList = {"TurteleDJ", "GreenTxrtIe", "NotKxng"} --remember to replace with UserIds!!

game:GetService("Players").PlayerAdded:Connect(function(plr)
        local ServerLockUI = plr:WaitForChild("PlayerGui").ServerIsLocked
        if ServerLocked.Value == true then
	        if table.find(WhiteList, plr.Name) then
		        print("Owner did join the game")
                        return end --do nothing but end
                else --not doing elseif saves time
			ServerLockUI.Enabled = true
			wait(100)
			plr:Kick("You are not allowed to join the game only game devs can join the game this game is in test proces")
		end
	end
end)

Your code is a little messy but this is what came up with.

Edit: If you’re restricting the game to devs only for a server lock I recommend just kicking the player right of the bat so they cannot see what you’re doing or testing.

2 Likes

Yeah sure. enabled should be Capitalized too.

2 Likes

So now i have this is this gonna work with the UI and the kick stuff

local ServerLocked = script.ServerLocked
local WhiteList = {"TurteleDJ", "GreenTxrtIe", "NotKxng"} --remember to replace with UserIds!!

game:GetService("Players").PlayerAdded:Connect(function(plr)
	local ServerLockUI = plr:WaitForChild("PlayerGui").ServerIsLocked
	if ServerLocked.Value == true then
		if table.find(WhiteList, plr.Name) then
			print("Owner did join the game")
			return end
	else
		local ServerLockUI = plr:WaitForChild("PlayerGui")
		ServerLockUI.ServerIsLocked.Enabled = true
		wait(100)
		plr:Kick("You are not allowed to join the game only game devs can join the game this game is in test proces")
	end
end
1 Like

It should, but keep in mind you’re not doing this with RemoteEvents and so making UI changes from the server is a sort of bad habit thing, but it should still work. Let me know if it doesn’t, if that’s the case add prints to your code.

1 Like

The Ui is still not coming up is there something what is not working cause i don’t get any errors

local ServerLocked = script.ServerLocked
local WhiteList = {"TurteleDJ", "GreenTxrtIe", "NotKxng"} --remember to replace with UserIds!!

game:GetService("Players").PlayerAdded:Connect(function(plr)
	local ServerLockUI = plr:WaitForChild("PlayerGui").ServerIsLocked
	if ServerLocked.Value == true then
		if table.find(WhiteList, plr.Name) then
			print("Owner did join the game")
			return end
	else
		local ServerLockUI = plr:WaitForChild("PlayerGui")
		ServerLockUI.ServerIsLocked.Enabled = true -- the problem needs to be here
		wait(100)
		plr:Kick("You are not allowed to join the game only game devs can join the game this game is in test proces")
	end
end
3 Likes
local ServerLockUI = plr:WaitForChild("PlayerGui")
		ServerLockUI.ServerIsLocked.Enabled = true
		wait(100)
		plr:Kick("You are not allowed to join the game only game devs can join the game this game is in test proces")

Here, remove .ServerIsLocked since I already indexed that in the variable.
It should be ServerLockUI.Enabled = true.

1 Like

the screen gui is named ServerIsLocked that’s why it is there so if i remove it it will not work right.

1 Like

Please re-read what I said

I already indexed that in the variable.

I already indexed your Gui under PlayerGui so it shouldn’t break, unless you changed the variable.
Keep the variable as

local ServerLockUI = plr:WaitForChild("PlayerGui").ServerIsLocked

and your enable UI as

ServerLockUI.Enabled = true
2 Likes

oh srr didn’t se the ServerIsLocked lol i will try it now

1 Like