I have no idea what i'm doing wrong but I am trying to make it so it doesn't destroy the gui if your name is in the admins table. How do I do this? Please use answers so I can reward you if your comment helped!
-----------Variables----------- admins = {"MillerrIAm",""} name = game.Players.LocalPlayer.Name -----------Main Code----------- if name == admins then wait() else script.Parent:Destroy() end
Thank you in advance!
Admins is a table, so your if statement will be always false. Use dictionary instead:
-----------Variables----------- admins = { ["MillerrIAm"] = true, ["Sleazel"] = true, --just joking, remove that line :) But that is how you add more admins } name = game.Players.LocalPlayer.Name -----------Main Code----------- if admins[name] then wait() else script.Parent:Destroy() end
BTW, make sure you check for admin privileges on server as well, otherwise it is a disaster waiting to happen.
You need to loop through the table to check if any of the values match your players name, shown below.
admins = {"metalive"} player = game.Players.LocalPlayer function checkWhitelist(playerName) local whitelisted = false for i,name in pairs(admins)do if playerName == name then whitelisted = true end end return whitelisted end if checkWhitelist(player.Name) then print("Whitelisted") else print("Player is not whitelisted") end
If you want to remove the GUI before it's loaded for the player then it needs to be in a server script. If you want to remove the GUI when the player joins then:
admins = {"metalive"} function checkWhitelist(playerName) local whitelisted = false for i,name in pairs(admins)do if playerName == name then whitelisted = true end end return whitelisted end game.Players.PlayerAdded:Connect(function(player) if checkWhitelist(player.Name) then print("Whitelisted") else local Ss, err = pcall(function() local playerGui = player:WaitForChild("PlayerGui") local gui = playerGui:WaitForChild("gui") gui:Destroy() end) if Ss then print("Gui removed") else warn(err) end end end)