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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
0
thanks for the correction, but i still need help with only allowing certain ranks only ingame Lengthtracked 5 — 6y
0
Okay. I will post edit this answer with improved code which you could use if you want. SomeRandomScorpion 1 — 6y
0
So you're telling me the owner can't join their own game? User#19524 175 — 6y
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. Lengthtracked 5 — 6y
View all comments (2 more)
0
and you should be using :Kick() not :kick() User#19524 175 — 6y
0
No. It's a VARIABLE. It can be changed to his/her liking. It doesn't have to be just "255". SomeRandomScorpion 1 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

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 5 — 6y
Log in to vote
-1
Answered by 6 years ago

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

0
Doesn't work, you didn't even check their rank. User#19524 175 — 6y

Answer this question