This is with name line being commented out.
This is with it not commented out:
Code that is having error:
local success, err = pcall(function()
local data = KillDataStore:GetSortedAsync(false, 50)
local page = data:GetCurrentPage()
for ranking, dataStored in ipairs(page) do
local userID = string.split(dataStored.key, "_")[2]
local name = game.Players:GetNameFromUserIdAsync(userID)
local kills = dataStored.value
print(name) -- returns correct name
local template = script.Template:Clone()
template["Name"].Text = name -- with this its broke, without it it works, like wtf??
template["Rank"].Text = "#" .. tostring(ranking)
template["Kills"].Text = tostring(kills)
template.Parent = script.Parent.Content
end
end)
I’ve tried everything I could think of, none of it works.
Full code
local DataStore = game:GetService("DataStoreService")
local KillDataStore = DataStore:GetOrderedDataStore("KillData")
local ResetTime = script.ResetTime.Value
while wait(1) do
ResetTime = ResetTime - 1
script.Parent.Timer.Text = "The leaderboard resets in <b>" .. ResetTime .. "</b> seconds."
if ResetTime == 0 then
ResetTime = script.ResetTime.Value
for _, player in pairs(game.Players:GetPlayers()) do
local success, err = pcall(function()
KillDataStore:SetAsync("Player_"..player.UserId, player:WaitForChild("leaderstats").Kills.Value)
end)
if success then
print("Success!")
end
end
for _, leaderboardFrame in pairs(script.Parent.Content:GetChildren()) do
if leaderboardFrame.ClassName == "Frame" then
leaderboardFrame:Destroy()
end
end
local success, err = pcall(function()
local data = KillDataStore:GetSortedAsync(false, 50)
local page = data:GetCurrentPage()
for ranking, dataStored in ipairs(page) do
local userID = string.split(dataStored.key, "_")[2]
local name = game.Players:GetNameFromUserIdAsync(userID)
local kills = dataStored.value
print(name) -- returns correct name
local template = script.Template:Clone()
template["Name"].Text = name -- with this its broke, without it it works, like wtf??
template["Rank"].Text = "#" .. tostring(ranking)
template["Kills"].Text = tostring(kills)
template.Parent = script.Parent.Content
end
end)
end
end