Advertisement
Guest User

Ranking Command Script

a guest
Feb 16th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. local gameKey = "" -- goes here
  2. local _Ranking = require(01896155381)(gameKey)
  3.  
  4.  
  5. local _Players = game:GetService("Players")
  6. local _Group = game:GetService("GroupService")
  7.  
  8.  
  9. local Command = "!rank" — change to whatever
  10. local GroupId -- set to group ID ofc
  11. local minRank -- set to min rank
  12.  
  13.  
  14. local function IsCommand(Message)
  15.     local search = string.find(Message, "^" .. Command)
  16.     return (search>-1 and true) or false
  17. end
  18.  
  19. local function Parse(Message)
  20.     local Words = {}
  21.     for str in string.gmatch(Message, "[%w]+") do
  22.         table.insert(Words, str)
  23.     end
  24.     return Words
  25. end
  26.  
  27. local function GetPlayer(String)
  28.     for i, plr in pairs(_Players:GetPlayers()) do
  29.         if (String:lower() == plr.Name:lower():sub(1, String:len())) then
  30.             return plr
  31.         end
  32.     end
  33. end
  34.  
  35. local function GetRank(Role)
  36.     local GroupInfo = _Group:GetGroupInfoAsync(GroupId)
  37.     for i, info in pairs(GroupInfo.Roles) do
  38.         if (info.Name:lower() == Role:lower()) then
  39.             return info.Rank
  40.         end
  41.     end
  42. end
  43.  
  44. local function Refresh(Player)
  45.     if (Player.Character) then
  46.         local Cframe = Player.Character.PrimaryPart.CFrame
  47.         Player:LoadCharacter()
  48.         local Char = Player.Character or Player.CharacterAdded;Wait()
  49.         Char:SetPrimaryPartCFrame(Cframe)
  50.     end
  51. end
  52.  
  53. local function Process(Message)
  54.     local MsgIsCmd = IsCommand(Message)
  55.     if (MsgIsCmd) then
  56.         local Words = Parse(Message)
  57.         local isPlayer = GetPlayer(Words[2])
  58.         if (isPlayer) then
  59.             local newRank = GetRank(table.concat(Words, “ “, 3))
  60.             if (newRank) then
  61.                _Ranking.setRank(GroupId, isPlayer.UserId, newRank)
  62.                     wait()
  63.                     Refresh(isPlayer)
  64.             end
  65.         end
  66.     end
  67. end
  68.  
  69.  
  70. _Players.PlayerAdded:Connect(function(Player)
  71.     local pRank = Player:GetRankInGroup(GroupId)
  72.     Player.Chatted:Connect(function(Message)
  73.         if (pRank>=minRank) then
  74.             Process(Message)
  75.         end
  76.     end)
  77.     Player.CharacterAdded:Connect(function()
  78.         pRank = Player:GetRankInGroup(GroupId)
  79.     end)
  80. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement