Yo I’m fairly new to coding and I’ve recently been learning from the Lua learn game but they didn’t have a section on there for “time trial leaderboards.” For some reason my script here in serverscriptservice will not display the times on the leaderboard I made and I followed a tutorial from youtube word for word, letter by letter. I don’t know if something’s outdated or what but I’ve been struggling with this since early September. I’ve asked for help countless times but people just skip over my posts I guess so I just resorted to trying it on my own and it didn’t work out too well! Here’s the leaderboard script below. I’ll look at y’all’s replies (if there are any ) when I wake up and I appreciate you for reading! Thank you and have a wonderful rest of your night. If you need a little more info you can just click my profile and go to my activity and/or go to the thread below:
local leaderboardStore = dataStoreService:GetOrderedDataStore("Leaderboard")
local Players = game:GetService("Players")
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, time)
time = math.floor(time * 1000)
leaderboardStore:UpdateAsync(player.UserId, function(oldTime)
if not oldTime then
oldTime = math.huge
end
if time < oldTime then
return time
else
return
end
end)
end)
local LeaderPart = workspace:WaitForChild("LeaderPart")
local surfacegui = LeaderPart.LeaderboardGui
local positionLabels = {
surfacegui:WaitForChild(1),
surfacegui:WaitForChild(2),
surfacegui:WaitForChild(3),
surfacegui:WaitForChild(4),
surfacegui:WaitForChild(5),
}
local function updateLeaderboard()
local leaderboardData = leaderboardStore:GetSortedAsync(true, 5)
local currentpage = leaderboardData:GetCurrentPage()
for i, data in ipairs(currentpage) do
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 - %.3f", 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()
Hey! This may or may not be much help because I must confess I never use ordered data stores for my leaderboards, but I believe that your “data.value” should be “data.Value.” Capitalize the “V!”
I believe that is something I learned a long time ago; maybe my memory is failing me, but if I’m correct, that might just be your issue.
I think you may need to have the numbers in quotation marks
i.e.
local positionLabels = {
surfacegui:WaitForChild('1'),
surfacegui:WaitForChild('2'),
surfacegui:WaitForChild('3'),
surfacegui:WaitForChild('4'),
surfacegui:WaitForChild('5'),
}
Also, as the person above said, you should use a capital V for .Value. Although it will still likely accept it, lowercase value is deprecated and not recommended for future use.
Preciate the help brother, I changed all the variables and stuff in the script and made sure they matched with the leaderboard part in workspace too but those errors above were displayed. Also here’s the changed script just incase y’all wanna know what I changed:
local dataStoreService = game:GetService("DataStoreService")
local leaderboardStore = dataStoreService:GetOrderedDataStore("Leaderboard")
local Players = game:GetService("Players")
replicatedStorage.BestTime.OnServerEvent:Connect(function(player, Time)
Time = math.floor(Time * 1000)
leaderboardStore:UpdateAsync(player.UserId, function(oldTime)
if not oldTime then
oldTime = math.huge
end
if Time < oldTime then
return Time
else
return
end
end)
end)
local LeaderboardPart = workspace:WaitForChild("LeaderboardPart")
local surfacegui = LeaderboardPart.LeaderboardGui
local positionLabels = {
surfacegui:WaitForChild("1"),
surfacegui:WaitForChild("2"),
surfacegui:WaitForChild("3"),
surfacegui:WaitForChild("4"),
surfacegui:WaitForChild("5"),
}
local function updateLeaderboard()
local leaderboardData = leaderboardStore:GetSortedAsync(true, 5)
local currentpage = leaderboardData:GetCurrentPage()
for i, data in ipairs(currentpage) do
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 - %.3f", i, player, Time)
else
positionLabel.Text = ""
end
end
end
end
updateLeaderboard()