Example: Promotion commands
A real-world example of using BloxTech Ranking to promote players in-game
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local GROUP_ID = 0
local MIN_RANK_TO_PROMOTE = 255
local BloxTech = require(ServerStorage:WaitForChild("BloxTechAPI"))
local BloxTechClient = BloxTech.new()
local function getPlayerFromPartialName(partialName)
local foundPlayer = nil
for _, player in ipairs(Players:GetPlayers()) do
if string.lower(player.Name):sub(1, #partialName) == string.lower(partialName) then
foundPlayer = player
break
end
end
return foundPlayer
end
local function getNextRankId(currentRankId)
local success, groupInfo = pcall(function()
return GroupService:GetGroupInfoAsync(GROUP_ID)
end)
if not success then
warn("Failed to fetch group info")
return nil
end
local roles = groupInfo.Roles
table.sort(roles, function(a, b)
return a.Rank < b.Rank
end)
for i, role in ipairs(roles) do
if role.Rank == currentRankId then
if roles[i + 1] then
return roles[i + 1].Rank, roles[i + 1].Name
else
return nil
end
end
end
return nil
end
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local args = string.split(message, " ")
local command = args[1]
if string.lower(command) == "/promote" then
if player:GetRankInGroup(GROUP_ID) < MIN_RANK_TO_PROMOTE then
print("You do not have permission to use this command.")
return
end
local targetName = args[2]
if not targetName then
print("Missing player name.")
return
end
local targetPlayer = getPlayerFromPartialName(targetName)
if not targetPlayer then
print("Player not found.")
return
end
local currentRankId = targetPlayer:GetRankInGroup(GROUP_ID)
local nextRankId, nextRankName = getNextRankId(currentRankId)
if not nextRankId then
print(targetPlayer.Name .. " is already at the highest rank or rank not found.")
return
end
print("Promoting " .. targetPlayer.Name .. " to " .. nextRankName .. " (" .. nextRankId .. ")...")
BloxTechClient:setRank(targetPlayer.UserId, nextRankId)
:andThen(function(response)
print("Successfully promoted " .. targetPlayer.Name .. "!")
end)
:catch(function(err)
warn("Failed to promote: " .. tostring(err))
end)
end
end)
end)Last updated
Was this helpful?