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

Admin commands are not working properly..?

Asked by
IcyEvil 260 Moderation Voter
6 years ago

No errors or anything, no clue whats wrong with this.

local owner = {game.CreatorId} -- add UserIds in this format 'game.CreatorId, 39493, 304034' etc..
local admin = {} -- add UserIds like above.

local Int = Instance.new('IntValue')

game.Players.PlayerAdded:connect(function(plr)
    for _,v in pairs(owner or admin) do
        if plr.UserId == v then
            print('hi')



        end
    end
end)
0
connect is deprecated. Use Connect. Thundermaker300 554 — 6y
0
Thunder, its deprecated which means it isn't being updated. 'connect' still works as of current. IcyEvil 260 — 6y

2 answers

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago

Eh, here let's start over, your script doesn't seem correct but your on to something.

First let's setup the variables and the event.

local owner = {game.CreatorId}
local admin = {}

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

end)

Next let's create a variable inside the event and then check through each id to see if the plr's id is in one of the tables

local owner = {game.CreatorId}
local admin = {}

game.Players.PlayerAdded:connect(function(plr)
    local isin = false
    for _,v in pairs(owner) do
        if v==plr.UserId then
            isin=true
            break
        end
    end
    if isin==false then
        for _,v in pairs(admin) do
            if v==plr.UserId then
                isin=true
                break
            end
        end
    end
    if isin==true then
        print("he's in")
    end
end)
0
Thank you. IcyEvil 260 — 6y
Ad
Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Expanding on Danz script; you can also use a dictionary array, which would allow you to check the table without running a for loop each time.

local admin = { 
    ['azarth'] = {creator = true, id = 312625920};
    ['danzlua'] = {creator = false, id = 12345};
}

-- Note that CreatorId will be 0 in studio.

local function player_joined(plr)
    local index = admin[plr.Name:lower()]
    if index then 
        if index.id == plr.UserId then 
            if index.creator then 
                print( string.format("%s is the creator", plr.Name))
            else
                print( string.format("%s is an admin", plr.Name))
            end
        else
            print( string.format("%s is a(n) %s, but the UserId didn't match.", plr.Name, index.creator and 'creator' or 'admin'))
        end
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    player_joined(plr)
end)

-- Catches the players that joined before PlayerAdded connected.
for i,v in pairs(game.Players:GetPlayers()) do
    player_joined(v)
end

Answer this question