Problems with a block of code in my script, arithmetic issues for a leaderboard

I just tried it and it’s still outputting 4598, I’ll try resetting the data store and I’ll let you know how it goes.

Okay so it works successfully BUT, it still shows a whole number on the leaderboard and when doing double digit numbers such as 11 seconds it will show 111 on the leaderboard. Here is the key shown for when I do single digit numbers, the number is 556 on the leaderboard it is only 5,
image

not quite sure if this is affecting it but

try

positionLabel.Text = i .. ". " .. player .. " - " .. time

looks very messy but it might make a difference. (i dont know much about format patterns)

Sorry for taking so long theres just some problem with the data store, I got them mixed up and they are just not working at all so the datastore is kind of just like not working but before changing the data store I tested that line of code and IT WORKS. thanks for figuring that out.

The value just outputs with this
image

And the script I am using right now…

local dataStoreService = game:GetService("DataStoreService")
local leaderboardStore = dataStoreService:GetOrderedDataStore("MainLeaderboard7")

replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
	time = math.floor(time * 100) -- dont divide it by 100 yet, because it would be a double.
	leaderboardStore:UpdateAsync(player.UserId, function(oldTime)
		oldTime = oldTime or print("Fail")
		return math.min(oldTime, time) -- put the bigger time to the leaderboard.
	end)
end)

local LeaderboardPart = workspace:WaitForChild("LeaderBoard")
local surfacegui = LeaderboardPart.LeaderboardGui
local positionLabels = {
	surfacegui:WaitForChild(1),
	surfacegui:WaitForChild(2),
	surfacegui:WaitForChild(3),
	surfacegui:WaitForChild(4),
	surfacegui:WaitForChild(5),
	surfacegui:WaitForChild(6),
	surfacegui:WaitForChild(7),
	surfacegui:WaitForChild(8),
	surfacegui:WaitForChild(9),
	surfacegui:WaitForChild(10),
}

local function updateLeaderboard()
	local leaderboardData = leaderboardStore:GetSortedAsync(true, 10)
	local currentPage = leaderboardData:GetCurrentPage()
	for i, data in ipairs(currentPage) do
		print(data)
		print(time)
		local time = data.value/100 -- make it a good looking decimal.
		local positionLabel = positionLabels[i]
		if positionLabel then
			local player = game:GetService("Players"):GetNameFromUserIdAsync(data.key)
			if player then
				positionLabel.Text = i .. ". " .. player .. " - " .. time
			else
				positionLabel.Text = ""
			end
		end
	end
end

replicatedStorage.BestTime.OnServerEvent:Connect(updateLeaderboard)

updateLeaderboard()
1 Like

sounds good, if you encounter any further errors just reply to me. i’m very tired so i’ll help with any errors tomorrow

1 Like

Alright man, good night and thanks for the help if I don’t find any issues ill mark your response as a solution.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.