I have a script here and it doesn't work for some reason. It is suppose to confirm if your an admin or not. I wonder what is wrong with my script
local UserName = {"InsertNameHere","voidofdeathfire"} game.Players.PlayerAdded:Connect(function(player) print(player.Name) if player.Name == UserName then while true do wait(1) print("ADMIN") end end end)
Here's the easier way:
It isn't where you have to type the exact player name with the correct capitalization. It allows you to just type it like, for example, Johny. You can type it like JoHnY and it still counts as a player name.
But I still recommend using user Ids in case of a user changing their username.
local administratorList = {} local function checkAdministratorStatus(player) local loweredPlayerName = string.lower(player.Name) for _,Administrator in next,administratorList do local loweredAdministratorName = string.lower(player.Name) if loweredPlayerName == loweredAdministratorName then return true end end end
User Id Version:
local administratorList = {} local function checkAdministratorStatus(player) for _,Administrator in next,administratorList do if player.UserId == Administrator then return true end end end
You are comparing a single string to a table. What you need to do is compare the contents inside the table (strings) with the username string. There are two ways to do this:
Firstly is a "for loop" with a regular table:
local Administrators = { "Player1", "Player2" } game.Players.PlayerAdded:Connect(function(player) for _, adminName in pairs(Administrators) do if player.Name == adminName then print("Administrator") end end end)
Another alternative is to use a dictionary:
local Administrators = { ["Player1"] = true, ["Player2"] = true } game.Players.PlayerAdded:Connect(function(player) if Administrators[player.Name] then print("Admin") end end)
This works because if the key (player name) exists in the dictionary of Administrator names, it will evaluate to true. If not, it will evaluate to nil