I want to make a gui leaderboard which duplicates the sample and puts it in the scrollingframe
but the problem is that the frames inside of the scrollingframe are not visible even though they’re inside.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local dataStore = DataStoreService:GetOrderedDataStore(timeCounters) -- Use a unique name for the datastore
--gui leaderboard
local GuiPlayers = StarterGui.InSafeZoneUI.FullScreen.TopTimeRankings.ScrollingTimeGui
local GuiSampleFrame = ReplicatedStorage.ReplicatedObjects.HolderFrameGuiTime
--physical leaderboard
local sample = ReplicatedStorage.ReplicatedObjects.LeaderBoardFrame
local sf = game.Workspace.TimeLeaderBoard.LeaderBoardContent.LeaderBoardPlayers
--gradients
local GoldGradient = ReplicatedStorage.ReplicatedObjects.GoldGradient
local SilverGradient = ReplicatedStorage.ReplicatedObjects.SilverGradient
local BronzeGradient = ReplicatedStorage.ReplicatedObjects.BronzeGradient
local function ApplyGradient(element, gradient)
local clonedGradient = gradient:Clone()
clonedGradient.Parent = element
end
-- Function to update the leaderboard data
local function updateLeaderboard()
for player, time in pairs(timeCounters) do
dataStore:SetAsync(player, time)
end
local pages = dataStore:GetSortedAsync(false, 100)
local top = pages:GetCurrentPage()
-- Clear the previous entries
for _, child in ipairs(sf:GetChildren()) do
if child:IsA("Frame") then
child:Destroy()
end
end
for _, child in ipairs(GuiPlayers:GetChildren()) do
if child:IsA("Frame") then
child:Destroy()
end
end
for rank, time in ipairs(top) do
local userId = time.key
local playerName = "Unknown Player"
local success, username = pcall(function()
return Players:GetNameFromUserIdAsync(userId)
end)
local time = time.value -- Use the value from the datastore directly
if success then
playerName = username
else
warn("Error fetching username for UserId:", userId)
end
local newEntry = sample:Clone()
newEntry.Parent = sf
newEntry.Name = "Entry" .. rank
newEntry.Rank.Text = rank
newEntry.PlayerName.Text = playerName
newEntry.TimeScore.Text = time
if rank == 1 then
ApplyGradient(newEntry.PlayerName, GoldGradient)
ApplyGradient(newEntry.Rank, GoldGradient)
newEntry.TimeScore.TextColor3 = Color3.new(255, 255, 255)
ApplyGradient(newEntry.TimeScore, GoldGradient)
elseif rank == 2 then
ApplyGradient(newEntry.PlayerName, BronzeGradient)
ApplyGradient(newEntry.Rank, BronzeGradient)
newEntry.TimeScore.TextColor3 = Color3.new(255, 255, 255)
ApplyGradient(newEntry.TimeScore, BronzeGradient)
elseif rank == 3 then
ApplyGradient(newEntry.PlayerName, SilverGradient)
ApplyGradient(newEntry.Rank, SilverGradient)
newEntry.TimeScore.TextColor3 = Color3.new(255, 255, 255)
ApplyGradient(newEntry.TimeScore, SilverGradient)
end
local NewGuiEntry = GuiSampleFrame:Clone()
NewGuiEntry.Parent = GuiPlayers
NewGuiEntry.Name = "Entry" .. rank
NewGuiEntry.RankGui.Text = rank
NewGuiEntry.PlayerNameGui.Text = playerName
NewGuiEntry.ScoreGui.Text = time
end
end
Players.PlayerAdded:Connect(updateLeaderboard)
-- Global variable to track the time until the next leaderboard update
local leaderboardUpdateCounter = 0
-- Schedule the leaderboard update function to run every 60 seconds
while true do wait(1)
leaderboardUpdateCounter = leaderboardUpdateCounter + 1
if leaderboardUpdateCounter >= 20 then
leaderboardUpdateCounter = 0
updateLeaderboard()
end
end