A ui opening only for certain people

the title says everything

heres my script that didnt worked:

local admin = {
	"LLOLOLOil",
	"westavengerNOOB",
	"patriziusmaximus",
	"LL0L0L0il",
	"Tim0XBeR",
	"oiy_z"
}

game.Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " has joined the game.") -- Debug statement
	for i, v in pairs(admin) do
		if player.Name == v then
			print(player.Name .. " is an admin!") -- Debug statement
			script.Parent.Visible = true
			break -- Exit the loop early once a match is found
		end
	end
end)

Instead of using a for loop just use table.find

game.Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " has joined the game.") -- Debug statement
	if table.find(admin, player.Name) then
		script.Parent.Visible = true
	end
end)

thanks

words words words words

oh well it does not work, the ui is still invisible

Could I see the UI’s hierarchy

image
note: the “Other” screengui is parented to startergui, no folder or stuff

In this case you shouldn’t be using Players.PlayerAdded.
Instead do

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer

if table.find(admin, LocalPlayer.Name) then
	script.Parent.Visible = true
end

Do keep in mind that an exploiter would still be able to gain access to this GUI, so ensure your server side logic is protected from exploiters.

1 Like

it worked, thanks for helping

words words words