Now I am developing an online school
(GE International School)
where I give GE Point according to students’ activities.
Now I am making a global leaderboard according to this article and
the normal one showing accumulated GE Points is working.
However, when I add some codes (in the red rectangle) to make a daily leaderboard, it dosen’t work.(no errors are shown).
I think something wrong with how to script, but I don’t know how to change it.
I appreciate if someone help me.
I do not remember exactly how but here is an old code that I had made, maybe it will help you
local TeleportService = game:GetService("TeleportService")
local DataStoreService = game:GetService("DataStoreService")
local dataConfig = game.ReplicatedStorage.DataStoreConfig
local WinsLeaderboard = DataStoreService:GetOrderedDataStore(dataConfig.DataStorageName.Value)
local function updateLeaderboard()
local success, errorMessage = pcall (function()
local Data = WinsLeaderboard:GetSortedAsync(false, 7)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local totalXPearned = data.value
local isOnLeaderboard = false
for i, v in pairs(script.dir.Value:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
if totalXPearned and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Wins.Text = totalXPearned
newLbFrame.Rank.Text = Rank
--newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #script.dir.Value:GetChildren()), 0)
newLbFrame.Parent = script.dir.Value
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.UserId, player.totalXPearned.Value)
end
for _, frame in pairs (script.dir.Value:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10)
end
local teleportData = TeleportService:GetLocalPlayerTeleportData()
if teleportData then
local Player = game.Players:GetPlayerByUserId(teleportData.PlayerName)
Player:WaitForChild('totalXPearned').Value = Player.totalXPearned.Value + 1
end
the daily leaderboard doesnt work probably because what you did will only reset the key.
to make a daily leaderboard you will want to store the accumulated point NOT the total point.
basically what happen in the current one is :
a day passed
the leaderboard data key changed. which means the datastore is now an empty table
the player joined
after the player joined the empty datastore stores the current point, which makes it work just like the non-daily leaderboard, since the current point is the Total Point.
easy way to fix will be to add another Value named “Accumulated_Point” and reset it daily, use the “Accumulated_Point” to make the daily leaderboard not the Total Point.
WARNING : do not reset the “Accumulated_Point” before inserting the “Accumulated_Point” to leaderboard or else if you do it then the leaderboard wouldn’t work.