Global Leaderboard Few Errors pls help

i found an issue when every time the countdown ends it clones i how i want but when the count down ends again it clones again but it does not destroy the old one

heres the problems:

local DataStoreService = game:GetService("DataStoreService")
local TimeODS = DataStoreService:GetOrderedDataStore("lbSaved_1")


local timeUntilReset = 3


while wait(1) do


	timeUntilReset = timeUntilReset - 1

	script.Parent.Countdown.Text = timeUntilReset


	if timeUntilReset == 0 then

		timeUntilReset = 10


		for i, plr in pairs(game.Players:GetPlayers()) do

			TimeODS:SetAsync(plr.UserId, plr.leaderstats.Fish.Value)
		end

		for i, leaderboardRank in pairs(script.Parent:GetChildren()) do

			if leaderboardRank:IsA("Frame") then
				leaderboardRank:Destroy()
			end
		end


		local success, errorMsg = pcall(function()

			local data = TimeODS:GetSortedAsync(false, 5)
			local coinsPage = data:GetCurrentPage()

			for rankInLB, dataStored in ipairs(coinsPage) do


				local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
				local coins = dataStored.Value


				local template = script.Template:Clone()

				template.Parent = script.Parent.ScrollingFrame

				template.Name = name .. "Leaderboard"

				template.PlrName.Text = name

				template.Rank.Text = "#" .. rankInLB

				template.Minutes.Text = coins

			end         
		end)
	end
end

Try this, please tell me if it doesn’t work so I can fix it for you :smiley:

local DataStoreService = game:GetService("DataStoreService")
local TimeODS = DataStoreService:GetOrderedDataStore("lbSaved_1")


local timeUntilReset = 3


while wait(1) do


	timeUntilReset = timeUntilReset - 1

	script.Parent.Countdown.Text = timeUntilReset


	if timeUntilReset == 0 then

		timeUntilReset = 10


		for i, plr in pairs(game.Players:GetPlayers()) do

			TimeODS:SetAsync(plr.UserId, plr.leaderstats.Fish.Value)
		end

		for i, leaderboardRank in pairs(script.Parent:GetChildren()) do

			if leaderboardRank:IsA("Frame") then
				leaderboardRank:Destroy()
			end
		end


		local success, errorMsg = pcall(function()

			local data = TimeODS:GetSortedAsync(false, 5)
			local coinsPage = data:GetCurrentPage()

			for rankInLB, dataStored in ipairs(coinsPage) do


				local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
				local coins = dataStored.Value
				local Fish = game.Players.LocalPlayer.leaderstats.Fish.Value


				local template = script.Template:Clone()
				
				template.Parent = script.Parent.ScrollingFrame  

				template.Name = name .. "Leaderboard"

				template.PlrName.Text = name

				template.Rank.Text = "#" .. rankInLB

				template.Minutes.Text = Fish
          
			end         
		end)
	end
end
1 Like

In case you didnt notice, you posted the exact same script with no changes lol.

It seems you are trying to use DataStore in the same script as LocalPlayer, which is not allowed due to DataStore being ServerSided and LocalPlayer being ClientSided.

As for the Cloning issue, you would need to either remove existing templates from the ScrollingFrame or update any existing template that matches the name for each player.

No, LexiUniq just replaced:
image

with:
image

Oh good catch! I did not see it :smile:

1 Like

It was a simple mistake, the change was small and easy to overlook. Another person already pointed it out so this reply wasn’t necessary. :neutral_face:

1 Like

no i didnt work like nothing happens like nothing clones in scrolling frame

oh wait i forgot i needed to change something in script ima update the script

and it still clones the frame again without removing the old one

and the fish wont show in frame either well text

i umm made a vid up top so u can see