Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you make a table of names like lets say a list of admin names?

Asked by 6 years ago
Edited 6 years ago

so in my script, when you join the game the following code runs:

local Admins = {"PutNameHere", "cruizer_snowman"}

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Char)
        if Player:GetRankInGroup(2832687) == 3 then -- just a double check
            if Player.Name == Admins then -- checks if the players name is in the table of Admins
            game.ReplicatedStorage.AdminPannel:Clone()
            game.ReplicatedStorage.AdminPannel.Parent = Player.PlayerGui
            end
        end
    end)
    ---------------------------------------------
    local Folder = Instance.new("Folder", Player)
    Folder.Name = "leaderstats"
    ---------------------------
    local Warnings = Instance.new("IntValue", Player)
    Warnings.Name = "Warnings"
    Warnings.Value = 0
end)

to be honest, im not that great with tables :/ any help would be much appreciated!

3 answers

Log in to vote
3
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Incapaz's idea is good, however he forgot to mention that you would need to turn your table into a dictionary table.

A dictionary table looks like this:

local t = {
    Key = "value"
}

or

local t = {
    ["Key"] = "value"
}

So your table should look like this:

local Admins = {
    PutNameHere = true,
    cruizer_snowman = true,
}

And your full code, like this:

local Admins = {
    PutNameHere = true,
    cruizer_snowman = true,
}

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Char)
        if Player:GetRankInGroup(2832687) == 3 then -- just a double check
            if Admins[Player.Name] then -- checks if the players name is in the table of Admins
            game.ReplicatedStorage.AdminPannel:Clone()
            game.ReplicatedStorage.AdminPannel.Parent = Player.PlayerGui
            end
        end
    end)
    ---------------------------------------------
    local Folder = Instance.new("Folder", Player)
    Folder.Name = "leaderstats"
    ---------------------------
    local Warnings = Instance.new("IntValue", Player)
    Warnings.Name = "Warnings"
    Warnings.Value = 0
end)
0
Thanks! just tested and it works!! i also just learned some new stuff so, thank you! cruizer_snowman 117 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

Lines 3 and 4. Change :connect to :Connect, :connect is deprecated.

Line 6. You’re checking if the player’s name equals an entire table, which isn’t possible. So do this:

if Admins[Player.Name] then 
0
His table isn't a dictionary, but have an upvote anyways :3 Amiaa16 3227 — 6y
Log in to vote
1
Answered by 6 years ago

With any admin system you should be using the UserId as this will never change.

There are lots of ways you can check if the player is in the admin list but the simpler method would be to use a dictionary as you can look up the index quickly.

Lastly you also clone the AdminPannel but the clone is not used meaning you just change the parent of the admin panel. You also should probably put this admin gui in storage as normal player do not need it replicated to them.

Example:-

local Admins = {
    -- format player id =  name
    -- name is just a place holder
    [193019473] = "cruizer_snowman"
}

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Char)
        if Player:GetRankInGroup(2832687) == 3 then 
        -- index will be nil if not found 
            if Admins[Player.UserId]  then 
        -- clone and parent the gui
            game.ReplicatedStorage.AdminPannel:Clone().Parent = Player.PlayerGui
            end
        end
    end)
    ---------------------------------------------
    local Folder = Instance.new("Folder", Player)
    Folder.Name = "leaderstats"
    ---------------------------
    local Warnings = Instance.new("IntValue", Player)
    Warnings.Name = "Warnings"
    Warnings.Value = 0
end)

A better Idea would be to only connect the add admin panel function on CharacterAdded for admins only meaning you would only check if they are admin once.

I hope this helps.

0
Thanks! cruizer_snowman 117 — 6y

Answer this question