I am trying to make a “Top Donor” Text Label on my surface GUI. I used a tutorial off the devforum and changed it to fit my needs, but it doesn’t work and I don’t know why.
Script:
local DatastoreService = game:GetService('DataStoreService')
local Players = game:GetService('Players')
local DonatorsDatastore = DatastoreService:GetOrderedDataStore('Donators')
local refreshInterval = 5
local donatorsShown = 1
local function refresh()
-- get the donators
local pages: DataStorePages = DonatorsDatastore:GetSortedAsync(false, donatorsShown, 1, 2^63)
print("Got pages")
-- loop over the donators
-- rank is a range from 1 to #donatorsShown
-- data is a dictionary/table containing the userId and the amount donated
for rank, data in pages:GetCurrentPage() do
local userId = data.key
local amount = Players:GetPlayerByUserId(userId):WaitForChild("AmountDonated").Value
-- get the name based on the userId
local name = Players:GetNameFromUserIdAsync(userId)
-- get the headshot profile image of the donator
local profile = Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size48x48)
-- clone the donator frame
script.Parent.SurfaceGui.DonorName.Text = name
script.Parent.SurfaceGui.DonorImage.Image = profile
end
print("looped")
end
while true do
refresh()
print("refreshed")
task.wait(refreshInterval)
end