-
Achieving a Level-System Game.
-
I got problems with my Global Leaderboard it should look like this:
The TopBar is always there but the Template beneath is not.
The Template is broken into 3 Text labels (from left to right) Rank, Name and Level and inside a Frame put in ReplicatedStorage.
The way it should go is through the Workspace onto the Part into the Holder.
Here is my script:
local DataStoreService = game:GetService("DataStoreService")
local LevelLeaderboard = DataStoreService:GetOrderedDataStore("LevelLeaderboard")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = LevelLeaderboard:GetSortedAsync(false, 5)
local LevelPage = Data:GetCurrentPage()
for Rank, data in ipairs(LevelPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Level = data.Value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.TVLevelLeaderboard.TVFace.LeaderboardGUI.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
if Level and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.PName.Text = Name
newLbFrame.PLevel.Text = Level
newLbFrame.PRank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.TVLevelLeaderboard.TVFace.LeaderboardGUI.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.TVLevelLeaderboard.TVFace.LeaderboardGUI.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, Player in pairs(game.Players:GetPlayers()) do
LevelLeaderboard:SetAsync(Player.UserId, Player.leaderstats.Level.Value)
end
for _, frame in pairs(game.Workspace.TVLevelLeaderboard.TVFace.LeaderboardGUI.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10) --Will be set to 300
end
Tried changing the code for 2h hoping something else would happen. (I got no errorMessages through searching which means that I made no mistakes)
Prepared other Global Leaderboard methods but this one is still the best!
I was a lot online searching.