local dataStoreService = game:GetService("DataStoreService")
local leaderboardStore = dataStoreService:GetOrderedDataStore("MainLeaderboard4")
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
time = math.floor(time * 1000)
leaderboardStore:UpdateAsync(player.UserId, function(oldTime)
oldTime = oldTime or 0
return math.max(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(time)
local time = data.value/1000
local positionLabel = positionLabels[i]
if positionLabel then
local player = game:GetService("Players"):GetNameFromUserIdAsync(data.key)
if player then
positionLabel.Text = string.format("%d. %s - %d", i, player, time)
else
positionLabel.Text = ""
end
end
end
end
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
time = math.floor(time * 1000)
leaderboardStore:SetAsync(player.UserId, time)
updateLeaderboard()
end)
updateLeaderboard()
Sure, so say the value of the best time is 5.359, in the output data key it responds with 5359 but the actual leaderboard only rounds it to the nearest whole number which is 5, is there a way to just make it so that it shows the entire value instead of the whole number? The value uses your personal best score and puts it onto the leaderboard, if your personal best is lower than your new time score it will not update the personal best.
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
time = math.floor(time * 1000)
leaderboardStore:UpdateAsync(player.UserId, function(oldTime)
oldTime = oldTime or 0
return math.max(oldTime, time) -- put the bigger time to the leaderboard.
end)
end)
there’s clearly a math.floor there, which probably caused the issue. try removing math.floor and change the line to time = time * 1000
Done, nothing had changed the exact same outcome had been shown as the last image, I’m checking the script right now for more rounding or arithmetic let me know if you found anything.
local dataStoreService = game:GetService("DataStoreService")
local leaderboardStore = dataStoreService:GetOrderedDataStore("MainLeaderboard5")
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
time = time * 1000
leaderboardStore:UpdateAsync(player.UserId, function(oldTime)
oldTime = oldTime or 0
return math.max(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/1000
local positionLabel = positionLabels[i]
if positionLabel then
local player = game:GetService("Players"):GetNameFromUserIdAsync(data.key)
if player then
positionLabel.Text = string.format("%d. %s - %d", i, player, time)
else
positionLabel.Text = ""
end
end
end
end
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
time = math.floor(time * 1000)
leaderboardStore:SetAsync(player.UserId, time)
updateLeaderboard()
end)
updateLeaderboard()
I’ve added back the math.floor and there is no longer any output errors although they still show whole numbers in the leaderboard. Here is the script so far,
local dataStoreService = game:GetService("DataStoreService")
local leaderboardStore = dataStoreService:GetOrderedDataStore("MainLeaderboard6")
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
time = math.floor(time * 1000)
leaderboardStore:UpdateAsync(player.UserId, function(oldTime)
oldTime = oldTime or 0
return math.max(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/1000
local positionLabel = positionLabels[i]
if positionLabel then
local player = game:GetService("Players"):GetNameFromUserIdAsync(data.key)
if player then
positionLabel.Text = string.format("%d. %s - %d", i, player, time)
else
positionLabel.Text = ""
end
end
end
end
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
time = math.floor(time * 1000)
leaderboardStore:SetAsync(player.UserId, time)
updateLeaderboard()
end)
updateLeaderboard()
“double” is literally decimal numbers, like 1.23, 4.56 etc. so if you dont want to store doubles then you can limit the digits behind the dot limited to 2 digits (i think 3 is too long) with a trick like: math.floor(time*100)/100
the logic is like this:
for an example, time is 1.2345
if we use math.floor(time), it would return 1.
but, if we multiply it by 100 first it would be equal to: math.floor(123.45) and it will return 123.
if we divide 123 by 100, it would be 1.23;
without using code, if we limit 1.2345 to 2 decimal digits it would be 1.23 too.
but in this case, datastore doesn’t accept doubles (decimals), so we can divide the time stored by 100 when we update the leaderboard.
local dataStoreService = game:GetService("DataStoreService")
local leaderboardStore = dataStoreService:GetOrderedDataStore("MainLeaderboard5")
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 0
return math.max(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 = string.format("%d. %s - %d", i, player, time)
else
positionLabel.Text = ""
end
end
end
end
replicatedStorage.BestTime.OnServerEvent:Connect(updateLeaderboard)
updateLeaderboard()
i noticed that i wrote this reply too long, sorry lol
It’s the exact same script you posted but here you go anyways,
local dataStoreService = game:GetService("DataStoreService")
local leaderboardStore = dataStoreService:GetOrderedDataStore("MainLeaderboard5")
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 0
return math.max(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 = string.format("%d. %s - %d", i, player, time)
else
positionLabel.Text = ""
end
end
end
end
replicatedStorage.BestTime.OnServerEvent:Connect(updateLeaderboard)
updateLeaderboard()
mb it was my mistake from the beginning, it was supposed to be math.min not math.max since the leaderboard is showing people who finished it the quickest.
local dataStoreService = game:GetService("DataStoreService")
local leaderboardStore = dataStoreService:GetOrderedDataStore("MainLeaderboard5")
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 0
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 = string.format("%d. %s - %d", i, player, time)
else
positionLabel.Text = ""
end
end
end
end
replicatedStorage.BestTime.OnServerEvent:Connect(updateLeaderboard)
updateLeaderboard()