I didn’t even realise , 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