How to Create a Rank Management System using Glitch

I didn’t even realise :sweat_smile:, thanks for the help. Is everything else set up correctly though?

Content of Main
local HttpService = game:GetService("HttpService")
local Server = require(script.Server)
Content of Server (script)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local Server = require(game:GetService("ServerScriptService").Main.Server)

local GroupId = 6532113
local Gamepasses = {
    {
        RankId = 15, 
        Id = 9885569
    },
    {
        RankId = 25, 
        Id = 9885586
    },
	{
    	RankId = 10,
        Id = 9885669
    },
    {
        RankId = 20,
        Id = 9885638
    },
	{
    	RankId = 40,
        Id = 9885752
    },
    {
        RankId = 45,
        Id = 9885768
    },
	{
    	RankId = 50,
        Id = 9885786
    },
    {
        RankId = 30, 
        Id = 9885689
    },
	{
        RankId = 35, 
        Id = 9885735
    },
}

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, GamepassId, wasPurchased)
    if wasPurchased then
        for _, Gamepass in pairs(Gamepasses) do
            if Gamepass.Id == GamepassId then
                if Player:GetRankInGroup(GroupId) < Gamepass.RankId then -- We don't want to demote them, but idk why they'd buy a lower rank...
                    Server.SetRank(GroupId, Player.UserId, Gamepass.RankId)
                end
            end
        end
    end
end)

Players.PlayerAdded:Connect(function(Player)
    -- Less than the rank you're about to promote them to otherwise :shrug:
    local HighestRankId = 50
    for _, Gamepass in pairs(Gamepasses) do
        if Player:GetRankInGroup(GroupId) < Gamepass.RankId and MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Gamepass.Id) then
            HighestRankId = HighestRankId < Gamepass.RankId and Gamepass.RankId or HighestRankId  
        end
    end

    if HighestRankId > 0 then
        Server.SetRank(GroupId, Player.UserId, HighestRankId)
    end
end)
Content of Configs
return {
	-- NOTE: The final '/' in the URL is very important!
	["BaseUrl"] = "link"; -- The base URL of your deployed server. Example: http://test-app.glitch.me/ 
	["AUTH_KEY"] = "key"; -- Secret Key defined as 'auth_key' in the config.json file of your server
}

obviously replaced key and base url to my stuff

Content of Server (module script)

local Server = {}

local HttpService = game:GetService("HttpService")

local Configs = require(script.Parent.Configs)
 
local function Request(Function, RequestBody)
	
	--Before sending the request, add our auth_key to the body
	RequestBody["auth_key"] = Configs.AUTH_KEY
	
	local response = HttpService:RequestAsync(
		{
			-- The website to send the request to. Function is the extended part of the URL for specific functions.
			-- In this case, Function = 'GroupShout'
			-- Example: 
			--	"Configs.BaseUrl..Function" would be equal to: http://test-app.glitch.me/GroupShout
					
			Url = Configs.BaseUrl..Function, 

			-- The request method (all of ours will be POST)
			Method = "POST",

			-- We are sending JSON data in the body
			Headers = {
				["Content-Type"] = "application/json"
			},
			-- The body of the request containing the parameters for the request
			Body = HttpService:JSONEncode(RequestBody)
		}
	)
 
	if response.Success then
		print("Status code:", response.StatusCode, response.Body)
		print("Response body:\n", response.Body)
		
		return response.Body
	else
		print("The request failed:", response.StatusCode, response.Body)
		return response.Body
	end
end

Server.Promote = function(GroupId, UserId)
	assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
	assert(typeof(UserId) == "number", "Error: UserId must be an integer") -- Throw error if UserId is not an integer

	local Body = {
		Group = GroupId;
		Target = UserId;
	}
	
	 -- pcall the function 'Request', with arguments 'Promote' and Body
	local Success, Result = pcall(function()
	    return Request('Promote', Body)
	end)
	
	print(Result)
end

Server.Demote = function(GroupId, UserId)
	assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
	assert(typeof(UserId) == "number", "Error: UserId must be an integer") -- Throw error if UserId is not an integer
	
	local Body = {
		Group = GroupId;
		Target = UserId;
	}
	
	local Success, Result = pcall(function()
	    return Request('Demote', Body)
	end)
	
	print(Result)
end

Server.SetRank = function(GroupId, UserId, RankId)
	assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
	assert(typeof(UserId) == "number", "Error: UserId must be an integer") -- Throw error if UserId is not an integer
	assert(typeof(RankId) == "number", "Error: RankId must be an integer") -- Throw error if RankId is not an integer

	local Body = {
		Group = GroupId;
		Target = UserId;
		Rank = RankId;
	}
	
	local Success, Result = pcall(function()
	    return Request('SetRank', Body)
	end)
	
	print(Result)
end

Server.HandleJoinRequest = function(GroupId, PlayerUsername, Boolean)
	assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
	assert(typeof(PlayerUsername) == "string", "Error: PlayerUsername must be a string") -- Throw error if PlayerUsername is not a string
	assert(typeof(Boolean) == "boolean", "Error: Boolean must be a boolean value") -- Throw error if Boolean is not a boolean value

	local Body = {
		Group = GroupId;
		Username = PlayerUsername;
		Accept = Boolean; -- true or false
	}
	
	local Success, Result = pcall(function()
	    return Request('HandleJoinRequest', Body)
	end)
	
	print(Result)
end

Server.GroupShout = function(GroupId, ShoutMessage)
	assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
	assert(typeof(ShoutMessage) == "string", "Error: ShoutMessage must be a string") -- Throw error if ShoutMessage is not a string

	local Body = {
		Group = GroupId;
		Message = ShoutMessage;
	}
	
	local Success, Result = pcall(function()
	    return Request('GroupShout', Body)
	end)
	
	print(Result)
end

return Server

image

I would just move all of the contents in Server (Script) to Main.

Somewhat like what Vong25 said, you should only have 1 ‘Server’ script. This should be a module script. In the path to server, put ‘script.Server’, assuming the path is in Main and Server is also a child of it.

Also, the code for the gamepasses should be in Main. The title Server implies that it is in ServerScriptService.

how would you add the automatic cookie pool system as you stated earlier?

How would you integrate it with your project?

If you have trouble with it, create a reply here: Cookie Pool System

1 Like

How would I make a auto-accept join request center off of this?

Instead of ranking someone when they pass an application, use the join handle function.

2 Likes

Sorry I am not that good on scripting how would I make a script to run the accept join request on the event fire?

When the event is fired, .OnServerEvent, pass in the parameter of the player and a security code (suggested, handle how ever you want), then use:

For more on server events, check this out: RemoteEvent | Documentation - Roblox Creator Hub

1 Like

I am sorry, I am still confused. Any chance you can just make the simple script I just dont understand it.

No, I can not just make the script, sorry. I am here to help, not do it for you.

I can suggest you watch this tho: https://m.youtube.com/watch?v=3wkPekjQvKg

If you don’t understand a specific part, or need clarification, then you can ask here or message me.

You didn’t make this? Well, I don’t think your allowed to post somebody elses resources… I may be wrong.

This is a tutorial on how to use an open source API, not a resource.

The creator is just the person who can edit the GitHub scripts.

The creator of the current version did not create the original version.

1 Like

faso

Hey, I keep on getting the error above with Glitch.

Also, on Roblox, I get
HttpError: InvalidUrl.

Help please?

Make sure the link includes HTTP or HTTPS. For some reason your code won’t connect to the glitch site.

It does include both. My friend, who is a scripter has also looked into it and no fix for it too.

Would you mind including the script? (You can hash out the title part of the domain so that it looks something like https(s)://#####.glitch.me). Are you receiving any errors other than the InvalidUrl?

Hey there! Thanks for this, but I have one question. Where do I put the script that ranks the user, if they own those certain gamepasses. Do I put it in the main script, or…?

Added this part to the main post.