How to add rank command ontop of the existing tutorial?

I just finished the amazing promote and demote tutorial and it all worked super slick and I’m very thankful to Cookie for making such a great resource. I was wondering how I could go about having a command that works along the lines of: “!rank Name RankID”. I’m presuming I’d need to edit code both in editor and on the repo. Does anyone know how I can do this? Thanks!

1 Like

Actually, we don’t need to edit the repo.

We need to edit the code within roblox.

We already have the /group/rank/ endpoint.

You can go to, BaseURl/docs to see how that endpoint works.

If you need help scripting the part within roblox, let me know.

It would be great if you could advise me - I’m trying to learn Lua at the moment however I’m struggling with this bit. How could I go about scripting it? I see where I have to put it I think I’m just not sure how. Thanks!

Send me the main script within roblox please.

local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game.ReplicatedStorage
local AppUrl = script.AppUrl.Value
local ApiKey = script.ApiKey.Value
local Groupid = script.GroupId.Value
local MinRank = script.MinRank.Value
local prefix = "!"

local function FindPlr(plr)
	local foundPlr = nil
	local plrs = game.Players:GetPlayers()
	for i = 1, #plrs do
		local current = plrs[i]
		if string.lower(current.Name):sub(1, #plr) == string.lower(plr) then
			foundPlr = current.Name
			break
		end
	end
	return foundPlr
end


game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if player:GetRankInGroup(Groupid) >= 2 then
			local LowerCaseMessage = string.lower(msg)
			if string.find(LowerCaseMessage, "!promote") then
				local SplitMessage = string.split(msg, " ")
				local full_player = FindPlr(SplitMessage[2])
				if full_player == nil then
					local playerInstance = game.Players:FindFirstChild(player.Name)
					game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We couldn't find the player you wanted to promote!")
				else
					local playerInstance = game.Players:FindFirstChild(player.Name)
					game.ReplicatedStorage.Notify:FireClient(playerInstance, "Attempting.","Attempting to promote user...")
					local Url = script.AppUrl.Value.."group/promote?user_name="..full_player.."&key=" ..script.ApiKey.Value.."&groupid="..script.GroupId.Value
					local success, response = pcall(function()
						local response = HttpService:GetAsync(Url)
						local data = HttpService:JSONDecode(response)
					end)
					if success then
						game.ReplicatedStorage.Notify:FireClient(playerInstance, "Horrah!","We promoteed the user!")
					else
						game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We had problems promoting the user.")
					end
				end
			else if string.find(LowerCaseMessage, "!demote") then
					local SplitMessage = string.split(msg, " ")
					local full_player = FindPlr(SplitMessage[2])
					if full_player == nil then
						local playerInstance = game.Players:FindFirstChild(player.Name)
						game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We couldn't find the player you wanted to demote!")
					else
						local playerInstance = game.Players:FindFirstChild(player.Name)
						game.ReplicatedStorage.Notify:FireClient(playerInstance, "Attempting.","Attempting to demote user...")
						local Url = script.AppUrl.Value.."group/demote?user_name="..full_player.. "&key=" ..script.ApiKey.Value.. "&groupid=" ..script.GroupId.Value
						local success, response = pcall(function()
							local response = HttpService:GetAsync(Url)
							local data = HttpService:JSONDecode(response)
						end)
						if success then
							game.ReplicatedStorage.Notify:FireClient(playerInstance, "Horrah!","We demoted the user!")
						else
							game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We had problems demoting. the user.")
						end
					end
				end
			end
		end
	end)
end)

Alright, so how do you think you would make a new command?

I’d have to create a function with the parameters username and rankId and then somehow use that to update the group rank rather than just adding 1 to the current value. At least I think that’s how it would work?

Exactly, so we need to add a new command, get the the player and to get the rank Id we want to rank, then we need to call the rank endpoint to use the bot.

Can you guide me as to the syntax for that? I’m a bit lost.

I’m making the script right now.

Can you send me your “api link” please, no Api Key please.

https://roblox-ranking-lapd.herokuapp.com/ - is this what you mean?

1 Like

Thanks a ton by the way! You’ve been the best help.

If you visit the docs endpoint your will get some documentation on the api: FastAPI - Swagger UI (roblox-ranking-lapd.herokuapp.com)

This is the Rank Endpoint, so I will now integrate that into game.

Ahh I see! Man you are a legend. :pray:

Example of docs here:

Just finishing the script now.

I will add tags so you understand.

Try this new script:

local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game.ReplicatedStorage
local AppUrl = script.AppUrl.Value
local ApiKey = script.ApiKey.Value
local Groupid = script.GroupId.Value
local MinRank = script.MinRank.Value
local prefix = "!"

local function FindPlr(plr)
	local foundPlr = nil
	local plrs = game.Players:GetPlayers()
	for i = 1, #plrs do
		local current = plrs[i]
		if string.lower(current.Name):sub(1, #plr) == string.lower(plr) then
			foundPlr = current.Name
			break
		end
	end
	return foundPlr
end


game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if player:GetRankInGroup(Groupid) >= 2 then
			local LowerCaseMessage = string.lower(msg)
			if string.find(LowerCaseMessage, "!promote") then
				local SplitMessage = string.split(msg, " ")
				local full_player = FindPlr(SplitMessage[2])
				if full_player == nil then
					local playerInstance = game.Players:FindFirstChild(player.Name)
					game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We couldn't find the player you wanted to promote!")
				else
					local playerInstance = game.Players:FindFirstChild(player.Name)
					game.ReplicatedStorage.Notify:FireClient(playerInstance, "Attempting.","Attempting to promote user...")
					local Url = script.AppUrl.Value.."group/promote?user_name="..full_player.."&key=" ..script.ApiKey.Value.."&groupid="..script.GroupId.Value
					local success, response = pcall(function()
						local response = HttpService:GetAsync(Url)
						local data = HttpService:JSONDecode(response)
					end)
					if success then
						game.ReplicatedStorage.Notify:FireClient(playerInstance, "Horrah!","We promoteed the user!")
					else
						game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We had problems promoting the user.")
					end
				end
			else if string.find(LowerCaseMessage, "!demote") then
					local SplitMessage = string.split(msg, " ")
					local full_player = FindPlr(SplitMessage[2])
					if full_player == nil then
						local playerInstance = game.Players:FindFirstChild(player.Name)
						game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We couldn't find the player you wanted to demote!")
					else
						local playerInstance = game.Players:FindFirstChild(player.Name)
						game.ReplicatedStorage.Notify:FireClient(playerInstance, "Attempting.","Attempting to demote user...")
						local Url = script.AppUrl.Value.."group/demote?user_name="..full_player.. "&key=" ..script.ApiKey.Value.. "&groupid=" ..script.GroupId.Value
						local success, response = pcall(function()
							local response = HttpService:GetAsync(Url)
							local data = HttpService:JSONDecode(response)
						end)
						if success then
							game.ReplicatedStorage.Notify:FireClient(playerInstance, "Horrah!","We demoted the user!")
						else
							game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We had problems demoting. the user.")
						end
					end
				else if string.find(LowerCaseMessage, "!rank") then --Look for the rank command to be used
						local SplitMessage = string.split(msg, " ") --Split the message
						local full_player = FindPlr(SplitMessage[2]) --Get the 2nd word in the message
						local req_rank = FindPlr(SplitMessage[3]) --Get the 3rd word in the message
						if full_player == nil then --If the player doesn't exsist thenf fail.
							local playerInstance = game.Players:FindFirstChild(player.Name) --Get the player that sent the command.
							game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We couldn't find the player you wanted to demote!") --Notify the client that it failed.
						else --if player exsists
							local playerInstance = game.Players:FindFirstChild(player.Name) --Find player that sent command.
							game.ReplicatedStorage.Notify:FireClient(playerInstance, "Attempting.","Attempting to demote user...") --Send loading. 
							local Url = script.AppUrl.Value.."group/demote?user_name="..full_player.. "&key=" ..script.ApiKey.Value.. "&groupid=" ..script.GroupId.Value.. "&role_number=" ..req_rank --Add RoleNumber To The Data sent to the WebServer.
							local success, response = pcall(function() --Pcall for obvious reasons
								local response = HttpService:GetAsync(Url) --Send request to webserver
								local data = HttpService:JSONDecode(response) --Decode Json Data.
							end)
							if success then --test if worked.
								game.ReplicatedStorage.Notify:FireClient(playerInstance, "Horrah!","We changed the rank of the user the user!") --Custom edited the error messages.
							else
								game.ReplicatedStorage.Notify:FireClient(playerInstance, "Uh-Oh","We had problems changing the rank of the user.") --Custom edited the error messages.
							end
						end
					end
				end
			end
		end
    end)
end)

If it works please mark this solution!

Happy new year,

@Noah

Hey! It’s me on a new account as the old one said I’ve reached the maximum amount of replies for the first day and to wait 9 hours. (Hence the msg, sorry!) Basically, it says “Attempting to demote user” and then nothing happens. Do you know what could have caused this - thanks so much!

1 Like