Hey! I am working on displaying data on a leaderboard based on the variable: Score
, however it keeps showing me this message:
Here is the leaderboard (ignore the dummy, it was just for size referance)
The problem is: the frame for displaying the Data isn’t in the correct possition nor is showing the player’s score and name.
Here is the directory for the example Frame:
Here are the scripts that influences the problem in one way or another:
Data unload, packing and translating script:
local RepStore = game:GetService("ReplicatedStorage")
local SvrStore = game:GetService("ServerStorage")
local DatStore = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local PlayerDataFolder = RepStore.PlayerData
local InfoStore = DatStore:GetDataStore("PlayerData")
local ToCall = game.ServerStorage.Events.DataCall
function UnloadPlayerData(PlayerID)
local suc, err = pcall(function()
local PlayerData = InfoStore:GetAsync(PlayerID)
if not PlayerData then
warn("data empty")
PlayerData = {}
PlayerData.Level = 0
PlayerData.Score = 0
end
local PlayerFolder = Instance.new("Folder")
PlayerFolder.Name = PlayerID
PlayerFolder.Parent = PlayerDataFolder
for store, data in pairs(PlayerData) do
local IntHolder = Instance.new("IntValue")
IntHolder.Name = store
IntHolder.Value = data
IntHolder.Parent = PlayerFolder
end
end) if not suc then warn(err) end
end
function PackPlayerData(PlayerID)
local PlayerFolder = PlayerDataFolder:FindFirstChild(PlayerID)
local success, err = pcall(function()
if PlayerFolder then
local PlayerData = {}
for i, v in pairs(PlayerFolder:GetChildren()) do
PlayerData[v.Name] = v.Value
end
InfoStore:SetAsync(PlayerID,PlayerData)
end
end)
if success then
PlayerFolder:Destroy()
else
warn(err)
end
end
function TranslateCall(callData)
local suc, err = pcall(function()
for i, v in pairs(callData) do
local PlrId = v.PlrId
local Ttype = v.Type
local value = v.Value
local LPlrFol = PlayerDataFolder[PlrId]
local SVal = LPlrFol[Ttype]
SVal.Value = SVal.Value + value
end
end) if not suc then warn(err) end
end
Players.PlayerAdded:Connect(function(plr) UnloadPlayerData(plr.UserId) end)
Players.PlayerRemoving:Connect(function(plr) PackPlayerData(plr.UserId) end)
ToCall.Event:Connect(function(tab) TranslateCall(tab) end)
Data Autosaver
local DataStore = game:GetService("DataStoreService")
local RepStore = game:GetService("ReplicatedStorage")
local SvrStore = game:GetService("ServerStorage")
local SvrScript = game:GetService("ServerScriptService")
local OrdScore = DataStore:GetOrderedDataStore("OrderedPlayerScore")
local PlayerData = DataStore:GetDataStore("PlayerData")
local PlayerDataFol = RepStore.PlayerData
function SavePlayerData()
for Order, DataSet in pairs(PlayerDataFol:GetChildren()) do
local UserID = DataSet.Name
local ToSaveTable = {}
for i, v in pairs(DataSet:GetChildren()) do
ToSaveTable[v.Name] = v.Value
end
PlayerData:SetAsync(UserID,ToSaveTable)
OrdScore:SetAsync(UserID,ToSaveTable["Score"])
end
end
while true do
task.wait(30)
local suc, err = pcall(SavePlayerData)
if not suc then warn(err) end
end
Data-to-leaderboard manager
local DataStoreService = game:GetService("DataStoreService")
local OrderedPlayerScore = DataStoreService:GetOrderedDataStore("OrderedPlayerScore")
function SyncLeaderB()
local Data = OrderedPlayerScore:GetSortedAsync(false,10)
local CurPage = Data:GetCurrentPage()
for rank, inf in ipairs(CurPage) do
local Username = game.Players:GetNameFromUserIdAsync(tonumber(inf.key))
local Score = inf.Score
local isOnLB = false
for i, v in pairs(game.Workspace.ScoreLB.LBgui.CoreFrame.BaseFrame:GetChildren()) do
if v.NameF.Text == Username then
isOnLB = true
break
end
end
if isOnLB == false then
local NFrame = game.ServerStorage.Storage.GUI.PointFrame:Clone()
NFrame.Parent = game.Workspace.ScoreLB.LBgui.CoreFrame.BaseFrame
NFrame.Position = UDim2.fromScale(0,0) + UDim2.fromScale(0,0.9*rank)
NFrame.CountF.Text = Score
NFrame.NameF.Text = Username
end
end
end
while true do
task.wait(30)
local suc, err = pcall(SyncLeaderB)
if not suc then warn(err) end
end