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

Would this work for a basis of an admin commands script?

Asked by
IcyEvil 260 Moderation Voter
7 years ago
Edited 7 years ago

Alright, my previous question about admin commands was very helpful with the answers, however I am now in need of help again, I can't test them at the moment, so I need to know if I have created a good "Basis" for the admin commands as the entire script is within an anonymous function, and then then a function within it is the actual commands and levels, I need help with this part as I dont know if it would work.

local adminlist = {
[game.CreatorId] = {3},
[NormalAdminId] = {2},
[Moderator] = {1},
}
-- the level of the admin goes 3(Owner kind of commands, if the admin has this they have access to all commands), 2(General commands such as kick, ff, etc...), 1(commands like ff, tp, and msg, nothing abusive)
game.Players.PlayerAdded:connect(function(plr)
function levels()
for _,v in pairs(adminlist) do
if v == "3" then
-- add commands for level 3 users

elseif  v == "2" then
-- add commands for level 2 users

elseif  v == "1" then
-- add commands for level 1 users

elseif  plr ~= v then
print("IsNotAdmin")
end
end
end
end
end
end
end

levels()
end)

Any and all help works.

1 answer

Log in to vote
2
Answered by 7 years ago

1st pls can you format your code correctly by using tabs it makes it a lot easier to read where each end goes.

Currently your code will not work as you want it because this is a index value table

for _,v in pairs(adminlist) do -- if you wanted to do a index, value loop the format is for  [variable for index usualy i], [variable for value usualy v]
    if v == "3" then -- this will always run as you do not check the player userid so the first value in the table will allways be 3
    -- add commands for level 3 users

    elseif  v == "2" then
    -- add commands for level 2 users

    elseif  v == "1" then
    -- add commands for level 1 users
    elseif  plr ~= v then
        print("IsNotAdmin")
    end
end

You do no need to use the loops so lets fix this.

local adminlist = {
    -- so just to make 100% shure the [needs the user id] so we dont need loops
    [game.CreatorId] = {3},
    [NormalAdminId] = {2},
    [Moderator] = {1},
}

game.Players.PlayerAdded:connect(function(plr)

    local function levels(plr)
        if adminlist[plr.UserId] == 3 then
            -- level 3 cmds
        elseif adminlist[plr.UserId] == 2 then
            -- level 2 cmds
        elseif adminlist[plr.UserId] == 1 then
            -- level 1 cmds
        else
            -- this should never happern but o well
        end
    end

    if adminlist[plr.UserId] ~= nil then -- check that the user is in our list before adding things, nil is returned if not in list so this will not run
        levels(plr)
    end
end)
0
You're a smart fellow. User#11440 120 — 7y
0
;) I need a fun question to do User#5423 17 — 7y
0
Thank you! IcyEvil 260 — 7y
Ad

Answer this question