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)
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)
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)
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.
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.
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.
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.
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
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.
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
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.