Table.find() doesn't work?

I’m making a button for admins only and when I run this script in a “server” script nothing happens tried with the local script nothing. Does anybody know why?

allowed = {"V33S"}

game.Players.PlayerAdded:Connect(function(plr)
	if table.find(allowed, plr.Name) then
		script.Parent.Visible = true
	else
		script.Parent.Visible = false
	end
end)

I’m very confused on what you are trying to do. I assume you are trying to show a gui if your name is in the list?

Yes, a button actually.

limitlimit

Firstly, use userId. Also, is this in a LocalScript? If so, whos? If its the connecting player, its not running yet.

Secondly, do NOT store the admin gui in the PlayerGui or starter gui. Especially if its functional. You are just begging exploiters to take advantage of it that way. Put the gui in ServerStorage, and in a server script, run:

local allowed = {"ID of admin"}

game.Players.PlayerAdded:Connect(function(plr)
	if table.find(allowed, plr.UserId) then
        local gui = game.ServerStorage.ADMINGUINAME:Clone();
        gui.Parent = plr.PlayerGui;
        --Make sure the property of the screenGUI in question, ResetOnDeath is set to false so it doesn't get deleted
	end
end)

Alright I’ll give this a go quickly

You should be checking the LocalPlayer:

local allowed = {561213643} -- your userId
local plr = game:GetService("Players").LocalPlayer

if table.find(allowed, plr.UserId) then
		script.Parent.Visible = true
else
		script.Parent.Visible = false
end

Make sure this is a local script. Also, if this is some admin thing, PLEASE DO SERVER SIDED CHECKS.

1 Like

Hit me up on Discord if you have any trouble or questions in the future. I can respond faster and without issue there. Pneuma#2149

Doesn’t work I’m not sure why I added some checks and it doesn’t detect my userID.

Send ur code. I’ll check it

Figured it out its because my UserID was in a string.

ah. Good luck. Remember, anything client scripts can access or do, so can exploiters.
Doesn’t matter what you delete, they can bring it back from nil

Alright, thanks for the support/help.