Im currently scripting an admin gui and i ran into a problem: im using ipairs to check if the player is in the admin table. Now Player1 is ~= my name so it deletes the gui. Is there a function to check if a table contains a string?
plr = game.Players.LocalPlayer admins = {"OKRPLAY","Player1"} for i,v in ipairs(admins) do if v ~= plr.Name then script.Parent:Destroy() end end
There are some issues with your current script. Let's address these first. 'if v ~= plr.Name then' we'll say my name is 'Player1'. I'm an admin. But since it goes through all of the strings, if my name isn't 'OKRPLAY' then it will be deleted. With slight changes we end with this. If you don't want a function, slight changes will fix that.
local Admins = {"TeleMom", "Noobite"} function CheckAdmin(Plr) local Success = false for i,v in pairs(Admins) do -- Go through the admin list if Plr.Name == v then Success = true -- Indicate that it was a success return -- Player is an admin, don't waste time going through. end end return Success end
If the player is an admin then you get true. If not, you get a false.