How can I get this following player script working?

Hey everyone, I can figure out how to get my script working it dosent check if you are following me because when you join my game they still can use the gold spray regardless if they are following me.

type EndpointData = {
	nextPageCursor: string?,
	data: {
		[number]: {
			isDeleted: boolean,
			friendRequestScore: number,
			friendRequestRank: number,
			hasVerifiedBadge: boolean,
			description: string?,
			created: string?,
			isBanned: boolean,
			externalAppDisplayName: string?,
			id: number,
			name: string,
			displayName: string
		}
	}
}

type HttpRequestResponse = {
	Success: boolean,
	StatusCode: number,
	StatusMessage: string,
	Headers: { any },
	Body: any
}

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")
local HTTPService = game:GetService("HttpService")

local Profiles = require(ServerScriptService.Scripts.Data:FindFirstChild("Profile List"))

--: number

local TargetUserId = 3690340936  
Workspace:SetAttribute("FollowRequirement", TargetUserId)

local EndpointUrl = "https://friends.roproxy.com/v1/users/" .. TargetUserId .. "/followers"

function EndpointRequest(UserId: number, Cursor: string?): HttpRequestResponse?
	local Success: HttpRequestResponse? = nil

	while not Success do
		local PSuccess, PResult = pcall(function()
			return HTTPService:RequestAsync({
				Url = EndpointUrl .. "/followings?sortOrder=Desc&limit=100&cursor=" .. (Cursor or ""),
				Headers = {
					["Content-Type"] = "application/json",
					["job-id"] = game.JobId
				},
				Method = "GET"
			}) :: HttpRequestResponse | string
		end)

		if not PSuccess then
			if typeof(PResult) == "string" and PResult:match("Number of requests exceeded limit") then
				task.wait(10)
				continue
			end

			Success = nil
			break
		end

		Success = PResult :: HttpRequestResponse
	end

	return Success
end

function FetchFollow(UserId: number, Cursor: string?): EndpointData?
	local Result: HttpRequestResponse? = EndpointRequest(UserId, Cursor)

	if not Result then
		return
	end

	if not Result.Success or Result.StatusCode ~= 200 then
		return
	end

	local FollowData = HTTPService:JSONDecode(Result.Body) :: EndpointData
	return FollowData
end

function FetchUserFollowingStatus(UserId: number): boolean
	local NextCursor = nil

	repeat
		local Response: EndpointData? = FetchFollow(UserId, NextCursor)

		if not Response then
			break
		end

		for _, UserData in pairs(Response.data) do
			if UserData.id == TargetUserId then
				return true
			end
		end

		NextCursor = Response.nextPageCursor
	until NextCursor == nil

	return false
end

ReplicatedStorage.Remotes.FollowStatus.OnServerInvoke = function(Player: Player)
	local Status = FetchUserFollowingStatus(Player.UserId)

	if Status then
		Player:SetAttribute("GoldSpray", true) 
		if Profiles[Player.Name] then
			Profiles[Player.Name].Data.FollowerReward = true  
		end
		return true
	end

	return false
end

2 Likes