I added codes to my game and I want people to be following me to redeem them. I know this is possible as other games have this, I just can’t find any recent/updated posts with actual methods or anything that works.
Here’s my code:
local HttpService = game:GetService("HttpService")
local MessagingService = game:GetService("MessagingService")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataService = require(ServerScriptService.Setup.DataManager.DataService)
local EditFunctions = require(ServerScriptService.Setup.DataManager.EditFunctions)
local UserIDs = require(ReplicatedStorage.Modules.Data.UserIDs)
local DATABASE_SECRET = "blablabla"
local API_URL = `blablabla`
local REFRESH_TOPIC = "REFRESH_CODES"
local CodesService = {}
CodesService.Codes = {}
CodesService.Version = -1
local HttpService = game:GetService("HttpService")
local function isFollowing(followerId: number, targetIds: {number})
local filteredTargets = {}
for _, id in ipairs(targetIds) do
if id ~= followerId then
filteredTargets[id] = false
end
end
if next(filteredTargets) == nil then
return true
end
local cursor = ""
while true do
local url = "https://friends.swproxy.xyz/v1/users/" .. followerId ..
"/followings?limit=100&sortOrder=Asc" ..
(cursor ~= "" and "&cursor=" .. HttpService:UrlEncode(cursor) or "")
local headers = {
['x-api-key'] = 'blablablabla'
}
local success, response = pcall(function()
return HttpService:GetAsync(url, false, headers)
end)
if not success then
warn("Failed to fetch followings:", response)
return false
end
for _, entry in ipairs(response.Body or {}) do
if filteredTargets[entry.id] ~= nil then
filteredTargets[entry.id] = true
end
end
local allFollowed = true
for _, followed in pairs(filteredTargets) do
if not followed then
allFollowed = false
break
end
end
if allFollowed then
return true
end
local nextCursor = response.Body.nextPageCursor
if not nextCursor or nextCursor == "" then
print("no more pages")
break
end
cursor = nextCursor
task.wait(0.15)
end
return false
end
local function followsAdSomnum(userId: number)
return isFollowing(userId, {UserIDs.Kai})
end
function CodesService.GetMarksCodes()
return CodesService.Codes['marks'] or {}
end
function CodesService.GetCodes()
return CodesService.Codes or {}
end
function CodesService.GetVersion()
return CodesService.Version or -1
end
function CodesService.LoadCodes(): ()
local success, result = pcall(function()
return HttpService:GetAsync(API_URL)
end)
if not success then
warn(("CodesService :: HTTP Fail :: %s"):format(result))
return
end
local data = HttpService:JSONDecode(result)
if data.version ~= CodesService.Version then
CodesService.Version = data.version
CodesService.Codes = data.codes or {}
end
end
function CodesService.SubmitCode(player: Player, inputtedCode: string): string
local codeType = ""
local codeReward = ""
local codeExists = false
if CodesService.Codes['marks'] then
for code, reward in pairs(CodesService.Codes['marks']) do
if code == inputtedCode then
codeExists = true
codeReward = reward
codeType = "marks"
break
end
end
end
if codeExists == true then
local followsAdSomnum = followsAdSomnum(player.UserId)
if followsAdSomnum ~= true then
return "not_following"
end
local getProfile = DataService.GetProfile(player)
if not getProfile or getProfile == {} then return "" end
local redeem = EditFunctions.AddRedeemedCode(getProfile, inputtedCode)
if redeem == "success" then
if codeType == "marks" then
EditFunctions.Marks(player, getProfile, "increment", codeReward)
end
return "success"
elseif redeem == "reused" then
return "reused"
end
else
return "non_existent"
end
end
function CodesService.init(): ()
CodesService.LoadCodes()
pcall(function()
MessagingService:SubscribeAsync(REFRESH_TOPIC, function()
CodesService.LoadCodes()
end)
end)
ReplicatedStorage.Remotes.InterfaceComponents.Codes.ToServer.SubmitCode.OnServerInvoke = CodesService.SubmitCode
end
return CodesService
yes, the codes exist. this was working previously when it required you to follow 2 people, but i changed it to just 1 and now it’s broken, i’ve also tried reverting to the 2 people and it doesn’t work with that either so i think roblox changed something?
i dont know if i need the x-api-key, i asked my friend if he could try to fix it and he added that, and he added his proxy but it still doesn’t work