This first script is inside of the leaderboard and controls the updating of the GUI.
I was testing this script below in-game (the leaderboards are based on a person's best speed run time) and I got an error in the dev console saying the double is not allowed in datastores on line 24 and 44.
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local DataStore2 = require(ServerScriptService.DataStore2)
for i = 1,10 do
local Sam = script.Sample:Clone()
Sam.Name = i
Sam.Parent = script.parent.SurfaceGui.Frame.ScrollingFrame
Sam.UserPos.Text = "[".. tostring(i) .."]"
Sam.Score.Text = "Nil"
Sam.LayoutOrder = i
script.Parent.SurfaceGui.Frame.ScrollingFrame.CanvasSize = UDim2.new(0,0,0,50*i)
end
function UpdateGui()
for i,v in pairs(game.Players:GetChildren()) do
local bestTimeDataStore = DataStore2("BestTime", v)
local Data1 = bestTimeDataStore:Get("BestTime", true)
local Data = Data1 * 100
print(Data)
local Datastore = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreX1",2)
if Data ~= 6942000 then
Datastore:SetAsync(v.UserId,Data)
end
end
local Datastore = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreX1",2)
local Pages = Datastore:GetSortedAsync(true,25)
local Data = Pages:GetCurrentPage()
for k,v in pairs(Data) do
if tonumber(v.key) >=1 then
local Frame = script.Parent.SurfaceGui.Frame.ScrollingFrame:FindFirstChild(tostring(k))
if Frame and Datastore:GetAsync(v.key) ~= 6942000 then
Frame.Username.Text = game.Players:GetNameFromUserIdAsync(v.key)
Frame.Score.Text = tostring(Datastore:GetAsync(v.key)/100 .."s")
end
end
end
end
while true do
UpdateGui()
wait(2)
end
This next script is located in ServerScriptService, and it controls the DataStores as the person gets a new time. I am using DataStore2 and OrderedDataStore for this.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local DataStore2 = require(ServerScriptService.DataStore2)
local defaultValue = 69420
game.Players.PlayerAdded:Connect(function(plr)
local bestTimeDataStore = DataStore2("BestTime", plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local BestTime = Instance.new("NumberValue", leaderstats)
BestTime.Name = "BestTime"
BestTime.Value = 69420
local function bestTimeUpdate(updatedValue)
BestTime.Value = bestTimeDataStore:Get(updatedValue)
end
bestTimeUpdate(defaultValue)
bestTimeDataStore:OnUpdate(bestTimeUpdate)
end)
game.ReplicatedStorage.SendData.OnServerEvent:Connect(function(plr, FinalTime)
local bestTimeDataStore = DataStore2("BestTime", plr)
if FinalTime < plr.leaderstats.BestTime.Value or plr.leaderstats.BestTime.Value == 0 then
plr.leaderstats.BestTime.Value = FinalTime
bestTimeDataStore:Set(FinalTime, defaultValue)
end
end)
When the leaderboard fills up with ten players, and a player who is already on the leaderboard gets a better time, their time isn't replaced. However when the leaderboard was partially empty, the score was updating as normal, but there were sometimes two scores for the same player.
In conclusion, I would like some clarification and tips on how it would be possible to remove these errors and make sure the leaderboard updates properly (e.g. one person gets a better time than others, his time gets put in, and others times are shifted down).

5 comments
Can you please post your error
the errors were in developer console in an actual game, i don't have them anymore unfortunately, but all it said that double is not allowed in datastores on line 24 and 44.
these errors happen in the first script.
if you would like to see the game in which i was testing this in, it is called ttctest1 and it is located on my roblox profile
other than the dev console error, the code works as explained in the post, and all i need to fix are the sorting issues