#Script not showing follower count.

1 messages · Page 1 of 1 (latest)

regal violet
#

Hello. I have this script that's supposed to count the amount of followers you have, and display it on top of your character. For some reason, it only shows zero. Any thoughts?

Here's the code:
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

-- Uses RoProxy so Roblox allows the request
local FOLLOWER_URL = "https://friends.roblox.com/v1/users/%d/followers/count"

-- Gets follower count from website
local function getFollowers(userId)
local url = string.format(FOLLOWER_URL, userId)
local success, response = pcall(function()
return HttpService:GetAsync(url)

end)

if not success then
    warn("Failed to get followers for user:", userId)
    return 0
end

local data = HttpService:JSONDecode(response)
return data.count or 0

end

-- Creates billboard above head
local function makeBillboard(character, count)
local head = character:WaitForChild("Head")

local billboard = Instance.new("BillboardGui")
billboard.Name = "FollowerDisplay"
billboard.Size = UDim2.new(0, 150, 0, 50)
billboard.StudsOffset = Vector3.new(0, 2, 0)
billboard.AlwaysOnTop = true
billboard.Parent = head

local label = Instance.new("TextLabel")
label.Size = UDim2.new(1, 0, 1, 0)
label.BackgroundTransparency = 1
label.TextScaled = true
label.Text = "Followers: " .. count
label.Parent = billboard

end

-- When player joins
Players.PlayerAdded:Connect(function(player)
local followers = getFollowers(player.UserId)

player.CharacterAdded:Connect(function(char)
    makeBillboard(char, followers)
end)

end)

Yes, ChatGPT wrote the script. Been a long time since I've done any developing and I'm lazy.