-
What do you want to achieve? Trying to make a leaderboard gui update without duplicating the frames of the same person.
-
What is the issue? The issue is that the leaderboard duplicate the frames.
-
What solutions have you tried so far? Tryed changing the code but it still somehow does duplicate the frames
Can someone find why it does this.
Script 1 (Local)
local player = game.Players.LocalPlayer
local Frame = script.Parent
local Logo = script.Parent.Topbar.Button
-- Waits until the frame is visible
while true do
if Frame.Visible then
break
end
wait()
end
local Sample = script.Parent.ScrollingFrame.UIListLayout.Sample
local ScrollingFrame = script.Parent.ScrollingFrame
local UI = ScrollingFrame.UIListLayout
local player = game.Players.LocalPlayer
local Debounce = false
-- Gets the data from the server
game.ReplicatedStorage.Events.Leaderboard.OnClientEvent:Connect(function(player, name, number ,image ,val)
local ClonedSample = Sample:Clone()
ClonedSample.Name = name -- Set name for better recognition and debugging
ClonedSample.LayoutOrder = name
ClonedSample.Logo.Image = number
ClonedSample.Logo.Rank.Text = "#"..tostring(name)
ClonedSample.Player.Text = player
ClonedSample.Cash.Text = tostring(image)
ClonedSample.Parent = ScrollingFrame
print(player, name, number, image)
end)
-- Rotate Refresh Button
for i = 0,50,1 do
Logo.Rotation = Logo.Rotation + 20
wait(0.01)
end
wait(0.01)
Logo.Rotation = 0
-- Tells the server we need the data
game.ReplicatedStorage.Events.Leaderboard:FireServer(player)
wait(10)
-- Script gets destroyed
script:Destroy()
Script 2 (Local)
local player = game.Players.LocalPlayer
local ScrollingFrame = script.Parent.Parent.Parent.ScrollingFrame
local Sample = ScrollingFrame.UIListLayout
local UI = ScrollingFrame.UIListLayout
local Logo = script.Parent
local Debounce = false
while true do
if ScrollingFrame.Visible then
wait(10)
break
end
end
function Loop()
for i = 60,0,-1 do
print(i)
if i == 0 then
Debounce = false
end
wait(1)
end
end
game.ReplicatedStorage.Events.Leaderboard.OnClientEvent:Connect(function(player, name, number ,image ,val)
if Debounce then
local ScrollingFrame = script.Parent.Parent.Parent.ScrollingFrame
local Sample = ScrollingFrame.UIListLayout.Sample
local UI = ScrollingFrame.UIListLayout
local ClonedSample = Sample:Clone()
ClonedSample.Name = name -- Set name for better recognition and debugging
ClonedSample.LayoutOrder = name
ClonedSample.Logo.Image = number
ClonedSample.Logo.Rank.Text = "#"..tostring(name)
ClonedSample.Player.Text = player
ClonedSample.Cash.Text = tostring(image)
ClonedSample.Parent = ScrollingFrame
print(player, name, number, image)
end
end)
function UpdateLeaderboard()
for i = 0,50,1 do
Logo.Rotation = Logo.Rotation + 20
wait(0.01)
end
wait(0.01)
Logo.Rotation = 0
game.ReplicatedStorage.Events.Leaderboard:FireServer(player)
Loop()
end
-- Check if the player pressed the refresh button
Logo.MouseButton1Click:Connect(function()
if not Debounce then
Debounce = true
UI.Parent = script
ScrollingFrame:ClearAllChildren()
UI.Parent = ScrollingFrame
UpdateLeaderboard()
end
end)