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

How would I implement this to trigger only during group ID and certain rank in said group ID?

Asked by 7 years ago
Edited 7 years ago

End project, I want this to be able to tell me how many high ranks are in a server. I just cant figure out how to implement group ID, and count only a certain rank or above. Any help would be much appreciated.

while wait()do
    if game.Players.NumPlayers==1 then script.Parent.Text= ""..game.Players.NumPlayers.." player"       
        else
          script.Parent.Text= ""..game.Players.NumPlayers.." players"   
end 
end

2 answers

Log in to vote
2
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
7 years ago
Edited 3 years ago

Since it doesn't look like you put attempt into using the Group functions provided, I will give you some instructions on how to create the script you're looking for.

  1. You're first going to want to set up a function like so function GetGroupMemebers() where no arguments are necessarily required.
  2. Set up two variables, one of the high ranks of the group and one for the regular group members. Set those equal to zero as we will be counting with them.
  3. Create a for loop that will iterate through all players. My suggestion would be the in pairs generic for loop. for i,v in pairs(game.Players:GetPlayers()) do
    • What GetPlayers ends up doing is getting all the players in PlayersService into a table. The table can then be used in the generic for loop.
  4. You will want to have an if-then statement to determine if a person is in a group using :GetRankInGroup() on the player using the variable v defined in the for loop. v can be changed to whatever you want when you make the loop. Within the GetRankInGroup method, you want to put the Group's ID so the script knows where to look. Then with the if then statement you want to compare the result which the function will provide to the rank you want the user to have using greater than or equal to condition >=.
  5. Within that if-then statement, you're going to want to add on to how many HRs you have.

    if Condition then
        hr = hr + 1
    end
    
  6. Of course, not everyone will be a High Rank. You will want to add elseif inside the if-then statement. This will tell the script, alright since the player isn't a HR, let's see if they can pass this condition. With the elseif condition you will want to simply use IsInGroup() to determine if that player is in the group or not. Like with GetRankInGroup, you still need the GroupId as an argument to the method.

  7. Depending on what you want to do, at the end of the function you may want to return the results of the code or edit a GUI.

    function x()
        --CodeHere
        TextLabel.Text = "There are " .. hr .. " High Ranks and " .. groupmemembers .. " group members."
    end
    
  8. Now, I would not recommend using a while loop as this is inefficient when we have events which can tell us if a player has left or joined.

  9. Outside of the function at the bottom of the script you will want to add the PlayerAdded and PlayerRemoving events. With events we can call a function when a player is joining the game or leaving.

    game.Players.PlayerAdded:connect(x)
    game.Players.PlayerRemoving:connect(x)
    x() --Add this if you plan on going a Gui route as there may not be any joining or leaving players in a respawn.
    

At this point you should be set. I would just recommend you put more effort into your script and question content next time as this may be seen as a request. Scripting Helpers does not take requests and this was a long list of instructions to write up. If you have any questions, feel free to ask. If you finished the instructions and the script isn't working make a new question on the site.

Hopefully, this answered your question. If it did, do not forget to hit the accept answer button. If you have any questions, please ask them in the comments below.
0
I did attempt it several times over the course of several hours. I just posted my code at its last working point. SinsofFallenGods 50 — 7y
0
Which was sadly without all that D: SinsofFallenGods 50 — 7y
Ad
Log in to vote
1
Answered by
Poine 30
7 years ago

This should help you out! :)

http://wiki.roblox.com/index.php?title=API:Class/Player/GetRankInGroup

Answer this question