Hello! I am trying to make an in-game admin command to rank up people in the group from a roblox API called RocketApps.
Currently, I have all of this below. Why isn’t it working? Here is what gets printed in the output after I request/post the HTTP.
This is the Post Endpoint: https://roblox.rocketpanel.io/roblox/bots/:loaderid/rankingroup
ModuleScript
--// Services
local HttpService = game:GetService("HttpService");
local RocketBots = {}
RocketBots.__index = RocketBots;
--// Creates a bot object
function RocketBots.new(loaderId)
local BotObject = setmetatable({}, RocketBots);
BotObject.id = loaderId
return BotObject
end
--// Enviornment
local apiBase = "https://roblox.rocketpanel.io/roblox/bots"
local function http(loaderId, endpoint, method, body)
if (body) then
body = HttpService:JSONEncode(body)
end
local success, message = pcall(function()
local newURL = apiBase .. '/' .. loaderId .. endpoint
local Response = HttpService:RequestAsync({
Url = newURL,
Method = method,
Headers = {
["Content-Type"] = "application/json" -- When sending JSON, set this!
},
Body = body
});
return HttpService:JSONDecode(Response.Body)
end)
if (not success) then
return {success = false, response = message}
else
return message;
end
end
--// Functions for the bot object.
function RocketBots:GetInfo()
return http(self.id, '/', 'GET')
end
function RocketBots:GetJoinRequests()
return http(self.id, '/getjoinrequests', 'GET')
end
function RocketBots:Shout(message)
return http(self.id, '/shout', 'POST', {msg = message})
end
function RocketBots:MessageUser(userId: string, subject: string, message: string)
return http(self.id, '/messageuser', 'POST', { ["userId"] = userId, ["subject"] = subject, ["message"] = message })
end
function RocketBots:ApproveJoinRequest(userId: string)
return http(self.id, '/approvejoinrequest', 'POST', { ["userId"] = userId })
end
function RocketBots:DeclineJoinRequest(userId: string)
return http(self.id, '/declinejoinrequest', 'POST', { ["userId"] = userId })
end
function RocketBots:RankInGroup(userId: string, rank: string)
print('Before Ranking?')
return http(self.id, '/declinejoinrequest', 'POST', { ["userId"] = userId, ["rankId"] = rank })
end
function RocketBots:Exile(userId: string)
return http(self.id, '/exile', 'POST', { ["userId"] = userId})
end
return RocketBots
ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local RocketBot = require(ReplicatedStorage:WaitForChild('RocketBots'))
local RoleId --Replace 255 with the role id that you would like the user to be set t
local Admins = {}
local playerTable = {}
game.Players.PlayerAdded:Connect(function(player)
table.insert(Admins, player)
table.insert(playerTable, player)
end)
game.Players.PlayerRemoving:Connect(function(player)
local pos = table.find(playerTable, player)
table.remove(playerTable, pos)
end)
local Prefix = "!"
local Players = game:GetService("Players")
local Commands = {}
local rankId = {}
for i = 0, 255 do
table.insert(rankId, i)
end
local rank1 = false
local rank2 = false
local groupID = 8991276
local function IsAdmin(Player)
if Player:GetRankInGroup(groupID) >= 254 then
return true
else
return false
end
end
local function request(userId, rankId)
local response = HttpService:RequestAsync(
{
Url = "http://httpbin.org/post", -- This website helps debug HTTP requests
Method = "POST",
Headers = {
["Content-Type"] = "application/json" -- When sending JSON, set this!
},
Body = HttpService:JSONEncode({
userId,
rankId
})
}
)
-- Inspect the response table
if response.Success then
print("Status code:", response.StatusCode, response.StatusMessage)
print("Response body:\n", response.Body)
else
print("The request failed:", response.StatusCode, response.StatusMessage)
end
end
Commands.setrank = function(Sender,Arguments)
local playerToBeRanked
for i, v in pairs(game.Players:GetChildren()) do
if table.find(Arguments, string.lower(v.Name)) then
playerToBeRanked = v
rank1 = true
else
end
end
for i, value in ipairs(rankId) do
if Arguments[i] ~= Sender.Name or Arguments[i] == rankId[i] then
if Arguments[i] ~= nil then
local playerRank = Sender:GetRankInGroup(groupID)
if playerToBeRanked:GetRankInGroup(groupID) < playerRank then -- <= for testing
RoleId = Arguments[i]
rank2 = true
print(RoleId)
end
end
end
end
tick()
if rank1 and rank2 then
-- Remember to wrap the function in a 'pcall' to prevent the script from breaking if the request fails
local success, message = pcall(request(tostring(playerToBeRanked.UserId), tostring(RoleId)))
if not success then
print("Http Request failed:", message)
end
--RocketBot:RankInGroup(tostring(playerToBeRanked.UserId), tostring(RoleId))
end
rank1 = false
rank2 = false
end
local function ParseMessage(Player,Message)
Message = string.lower(Message)
local PrefixMatch = string.match(Message,"^"..Prefix)
if PrefixMatch then
Message = string.gsub(Message,PrefixMatch,"",1)
local Arguments = {}
for Argument in string.gmatch(Message,"[^%s]+") do
table.insert(Arguments,Argument)
end
local CommandName = Arguments[1]
table.remove(Arguments,1)
local CommandFunc = Commands[CommandName]
if CommandFunc ~= nil then
CommandFunc(Player,Arguments)
end
end
end
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if IsAdmin(Player) then
ParseMessage(Player,Message)
end
end)
end)