Advertisement
RoScripter

Ranking Commands

Jun 3rd, 2020
21,547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. local GlitchURL = "" --Place the glitch project URL inside of the quotes
  2.  
  3. function rankUser(UserId, RoleId)
  4.     game:GetService("HttpService"):GetAsync(GlitchURL .. "ranker?userid=" .. UserId .. "&rank=" .. RoleId)
  5. end
  6.  
  7. local groupId = 1234567 -- Place your group ID here
  8. local minimumRankToUseCommands = 254 -- Place the minimum rank to use ranking commands here
  9.  
  10. local groupService = game:GetService("GroupService")
  11. local groupInfo = groupService:GetGroupInfoAsync(groupId)
  12.  
  13. function getNextRank(CurrentRank)
  14.     for i = 1, #groupInfo.Roles do
  15.         local RankId = groupInfo.Roles[i].Rank
  16.         if RankId > CurrentRank then
  17.             return RankId
  18.         end
  19.     end
  20. end
  21.  
  22. function getPreviousRank(CurrentRank)
  23.     table.sort(groupInfo.Roles,     function(a,b) return a.Rank > b.Rank end)
  24.     for i = 1, #groupInfo.Roles do
  25.         local RankId = groupInfo.Roles[i].Rank
  26.         if RankId < CurrentRank then
  27.             return RankId
  28.         end
  29.     end
  30. end
  31.  
  32. game.Players.PlayerAdded:Connect(function(Player)
  33.     if Player:GetRankInGroup(groupId) >= minimumRankToUseCommands then
  34.         Player.Chatted:Connect(function(Message)
  35.             local LowerCaseMessage = string.lower(Message)
  36.             if not string.find(LowerCaseMessage, "!rank") and not string.find(LowerCaseMessage, "!promote") and not string.find(LowerCaseMessage, "!demote") then return end
  37.             local SplitMessage = string.split(Message, " ")
  38.             local PlayerToRank = game.Players[SplitMessage[2]]
  39.            
  40.             if Player:GetRankInGroup(groupId) >  PlayerToRank:GetRankInGroup(groupId) then
  41.                 if string.find(LowerCaseMessage, "!rank") then
  42.                     local RankId = SplitMessage[3]
  43.                     rankUser(PlayerToRank.UserId, RankId)
  44.                 elseif string.find(LowerCaseMessage, "!promote") then
  45.                     local PlayerCurrentRank = PlayerToRank:GetRankInGroup(groupId)
  46.                     local RankId = getNextRank(PlayerCurrentRank)
  47.                     rankUser(PlayerToRank.UserId, RankId)
  48.                 elseif string.find(LowerCaseMessage, "!demote") then
  49.                     local PlayerCurrentRank = PlayerToRank:GetRankInGroup(groupId)
  50.                     local RankId = getPreviousRank(PlayerCurrentRank)
  51.                     rankUser(PlayerToRank.UserId, RankId)
  52.                 end
  53.             end
  54.         end)
  55.     end
  56. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement