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

Need a little bit of help with a table?

Asked by
RjsMc 48
5 years ago
Edited 5 years ago

So I am making something which restricts players for joining apart from a player in a group with a certain role. I tried doing this:

local Roles = {
    255;
    253;
    252;
    251;
    248;
}

game.Players.PlayerAdded:Connect(function(Player)
    for i,v in ipairs(Roles) do


        if (Player:GetRankInGroup(-GROUPID-)) == v then -- Limits who joins
          print("Allow")

    else
      Player:Kick("Not allowed to join") -- Change kick message
     end
    end


end)

Now it does work, however if you are one of the ranks, then your not the other ranks so then you get kicked for not being those ranks. How would I fix this?

0
if all of the "allowable" ranks are above 248, why not just do if group rank >= 248? DinozCreates 1070 — 5y
0
Because notice how its- 248, then 251. 249, 250 are skipped so I cant do that RjsMc 48 — 5y
0
ah ok, ive never done anything with roles or ranks so i dont know how theyre structured DinozCreates 1070 — 5y
0
you could have your if statement check through the roles one at a time, Roles[1] or Roles[2] or etc, its a more messy way to do it but would remove the issue you're having. DinozCreates 1070 — 5y
0
Alright ill do that then. Thanks RjsMc 48 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Typing out what I said in the comment, I know its clunky and messy and theres a better way to do it so don't @ me.

local Roles = {
    255;
    253;
    252;
    251;
    248;
}

game.Players.PlayerAdded:Connect(function(Player)
    if (Player:GetRankInGroup(-GROUPID-)) == Roles[1] or (Player:GetRankInGroup(-GROUPID-)) == Roles[2] or (Player:GetRankInGroup(-GROUPID-)) == Roles[3] or (Player:GetRankInGroup(-GROUPID-)) == Roles[4] or (Player:GetRankInGroup(-GROUPID-)) == Roles[5] then -- super gross code ewww
        print("Allow")
    else
        Player:Kick("Not allowed to join") -- Change kick message
    end
end)
Ad

Answer this question