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

How to add rank as a requirement to join a game?

I don't want low-rank recruits joining the group game, I need a rank requirement that checks the group if they are high enough. I also want raiders to join so if you are part of the group you must be this rank to join.

GroupId = "210856"

function onPlayerEntered(newPlayer)
    if not newPlayer:IsInGroup(GroupId) then
        newPlayer:remove() 
    end
end

game.Players.PlayerAdded:connect(onPlayerEntered)

3 answers

Hi there Lengthtracked.

groupID = 210856 -- ID of the group you allow
rankID = 255 -- Role ID of the whitelisted members + or -

function onPlayerEntered(newPlayer)
    if not newPlayer:GetRoleInGroup(groupID) >= rankID then
        newPlayer:kick('You are not Whitelisted to join this game!') 
    end
end

game.Players.PlayerAdded:connect(onPlayerEntered)

6 comments

0

thanks for the correction, but i still need help with only allowing certain ranks only ingame

0

Okay. I will post edit this answer with improved code which you could use if you want.

0

So you're telling me the owner can't join their own game?

0

is it possible to have raiders still coming in and raiding? after all its a warzone, i was wondering if theres an exception for raiders.

0

and you should be using :Kick() not :kick()

0

No. It's a VARIABLE. It can be changed to his/her liking. It doesn't have to be just "255".

###For that, you would use the GetRankInGroup method. Also, group IDs are numbers, not strings.

local GroupId = 210856 -- use local variables

local function onPlayerEntered(newPlayer)
    if newPlayer:GetRankInGroup(GroupId) < 3 then
        -- if their rank is smaller than whatever the rank you want, 3 is an example
        newPlayer:Destroy() 
    end
end

game:GetService("Players").PlayerAdded:Connect(onPlayerEntered)

###On a side note, Instance:remove() and RBXScriptSignal:connect() are deprecated, use Instance:Destroy() and RBXScriptSignal:Connect() instead.

1 comment

0

could it also include a message that says to the group user your not the right rank, and also allows non-group raiders to join too?

Lengthtracked, to get a persons rank in a group you could use :GetRankInGroup() like this:

GroupId = "210856"

function onPlayerEntered(newPlayer)
    if not newPlayer:IsInGroup(GroupId) and not newPlayer:GetRankInGroup(GroupId) then -- if the rank is right and its in the group
          newPlayer:Kick("sorry") -- kick the player
    else -- you really dont need to do this
          print("YEY")
    end
end

game.Players.PlayerAdded:connect(onPlayerEntered)

for more info use this link https://wiki.roblox.com/index.php?title=API:Class/Player/GetRankInGroup

1 comment

0

Doesn't work, you didn't even check their rank.

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