✓ Accepted answer
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.
- You're first going to want to set up a function like so
function GetGroupMemebers() where no arguments are necessarily required.
- 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.
- 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.
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 >=.
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
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.
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()
TextLabel.Text = "There are " .. hr .. " High Ranks and " .. groupmemembers .. " group members."
end
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.
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()
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.
2 comments
I did attempt it several times over the course of several hours. I just posted my code at its last working point.
Which was sadly without all that D: