I need help with whitelist script

Hi, so i have this script it kicks me out even tho i have my name in there, it only works when its Only my name

local player = game.Players.LocalPlayer
local usernames= {
“Exgames78”,
“IK3As”,
“FusionzManaphy”,
“DaRealSkipp”,
“DerpyDervee”,
“ARseNl_AlMb0T”,
“SimplyJustMono”,
“AP0110_Dev”

}

game.Players.PlayerAdded:Connect(function(plr)
for i, v in pairs(usernames) do
if v == plr.Name then
print(“Whitelisted”)
game.StarterGui.ScreenGui.Enabled = false

  else

  	game.StarterGui.ScreenGui.Enabled = true
  	wait(20)
  	plr:Kick("Not whitelisted")
  end

end
end)

the problem is probably because it doesnt check properly
i usually use table.find and i dont see anyone using pairs on a table
before putting this code below set enabled to false on screengui

local usernames = {
“Exgames78”,
“IK3As”,
“FusionzManaphy”,
“DaRealSkipp”,
“DerpyDervee”,
“ARseNl_AlMb0T”,
“SimplyJustMono”,
“AP0110_Dev”
}

game.Players.PlayerAdded:Connect(function(plr)
  	if not table.find(usernames, plr.Name) then
  	  	game.StarterGui.ScreenGui.Enabled = true
  	  	task.wait(20)
  	  	plr:Kick()
  	end
end)
1 Like

Gui code should be performed on the client (via a local script), you also need to reference the player’s ‘PlayerGui’ container not the shared ‘StarterGui’ container. I’d also recommend using user IDs instead of names as they cannot be changed.

local Game = game
local Script = script
local Players = Game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local ScreenGui = Script.Gui

local Whitelist = {} --Use IDs instead of names (names can be changed whereas IDs can't).
ScreenGui.Enabled = table.find(Whitelist, LocalPlayer.UserId)
2 Likes

you have forgotten that i wasnt the one making this topic also u need to put the kick function below screengui.enabled

The script just needs to enable/disable a ‘ScreenGui’ instance, kicking players is bad for UX (user experience).

personally i think exgames78 can do whatever to the game i dont really mind anyways

well this script was supposed for one of my game which i play with that small group of people i enumerated cuz is a small replica of a game where we would train and for the people that weren’t in the small group, i would just shown them this then kick them out