Global Leaderboard not working?

Oh so you did change that i didn’t know

Also it was where you saving the data
Check there

By the way could i see your script as it is currently?

1 Like

Let me send both scripts, the data saving and the leaderboard:

DataService:

local DataStoreService = game:GetService("DataStoreService")
local MarketplaceService = game:GetService("MarketplaceService")

local timeDataStore = DataStoreService:GetDataStore("timeDataStore")


local user

game.Players.PlayerAdded:Connect(function(player)
	
	
		
		
		user = player

		local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player

		local timePlayed = Instance.new("IntValue")
		timePlayed.Name = "TimePlayed"
		timePlayed.Parent = leaderstats

		local data

		local success, errormessage = pcall(function(player)
		data = timeDataStore:GetAsync(user.UserId)

		end)

		if success then
			timePlayed.Value = data

		else

			warn("There was a serious error loading data. They have been kicked to prvent dataloss. Error message:".. errormessage)
			user:Kick("There was a critical error loading your data. We had to kick you. Please provide this to the developer if this occurs again: ".. errormessage)

		end
		
		
	
	
	
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	
	local success, errormessage = pcall(function()
		
		timeDataStore:SetAsync(user.UserId, player.leaderstats.TimePlayed.Value)
		
	end)
	
	if success then
		print("Data has been saved!")
		
	else 
		
		print("There was an error when saving data.")
		print(errormessage)
	end

	
end)




		
	
	
	
local amount = 1
local timename = "TimePlayed"

while true do
	
		
		wait(60)
		for i,v in pairs (game.Players:GetPlayers()) do
			if v:FindFirstChild("leaderstats") then 
				v.leaderstats[timename].Value = v.leaderstats[timename].Value + amount
			end
		end



		local success, errormessage = pcall(function()

		timeDataStore:SetAsync(user.UserId, user.leaderstats.TimePlayed.Value)

		end)

		if success then
			print("Data has been saved!")

		else 

			print("There was an error when saving data.")
			wait(errormessage)
		end
		
		
	end

LeaderboardHandler:

local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("timeDataStore")

local function updateLeaderboard()
	--local success, errorMessage = pcall(function()
		local Data = WinsLeaderboard:GetSortedAsync(false, 5)
		local WinsPage = Data:GetCurrentPage()
	for Rank, Data in ipairs(WinsPage) do
		print(Data.key)
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(Data.key))
			local Name = userName
			local Time = Data.value
			local isOnLeaderboard = false
			for i, v in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end
		
		
			print(userName)
			if Time and isOnLeaderboard == false then
				
				local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
				newLbFrame.Player.Text = Name
				newLbFrame.Time.Text = Time
				newLbFrame.Rank.Text = "#"..Rank
				newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + .08 * #game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren(), 0)
				newLbFrame.Parent = game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder
			end
			
		
			
		end
		

		
		
		
		
	end
	
	


while true do
	
	for _, player in pairs (game.Players:GetPlayers()) do
		WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.TimePlayed.Value)
	end
	
	for _, frame in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
		frame:Destroy()
	end
	
	updateLeaderboard()
	print("Updated Leaderboard")
	
	

	
	wait(30)
	


	
end

Kind of a long shot, but can you try renaming the name of your datastore?

Good idea, this datastore name is totally messed up, so I’ll try that.

I’m hoping you’re just retrieving information that was “corrupted” by all the changes you made trying to solve this bug. I couldn’t find anything logically wrong with your code, but it is possible that I just missed something.

1 Like

Yea i agree with @v7zr i don’t see anything wrong with it so it might have been corrupted but ive never heard of this problem and i’ve made 10’s of edits to a data store with data saved in it
Hopefully that works for you

2 Likes

WOW! HA HA, I CANNOT BELIVE I JUST WASTED THAT MUCH TIME ON THIS! :sweat_smile: Jokes aside, thank you so much @v7zr and @starnova224. Sorry for all the wasted time!

2 Likes

No it’s ok you didn’t waste any time that error was probably recent since the original error was nothing close to this

1 Like