Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need a little bit of help with a table?

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?

5 comments

0

if all of the "allowable" ranks are above 248, why not just do if group rank >= 248?

0

Because notice how its- 248, then 251. 249, 250 are skipped so I cant do that

0

ah ok, ive never done anything with roles or ranks so i dont know how theyre structured

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.

0

Alright ill do that then. Thanks

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.