Hello people.
I'm trying to make a Roblox game with a leaderboard but it isn't going great. I'm not getting any errors but the script is still not working. By not working I mean nothing pops up on the Leaderboard. Nothing pops up in the console when I go into the game, only if I test it in Roblox Studio. Here is the game: https://www.roblox.com/games/6697835891/Legit-Parkour
Heres the code:
local DataStoreService = game:GetService("DataStoreService") local Coins = DataStoreService:GetOrderedDataStore("Coins") local function updateLeaderboard() local success, errorMessage = pcall(function() local Data = Coins:GetSortedAsync(false, 5) local CoinsPage = Data:GetCurrentPage() for Player, data in ipairs(CoinsPage) do local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key)) local Name = userName local Coins = data.value local isOnLeaderboard = false for i, v in pairs(game.Workspace.Leaderboard.SurfaceGui.Holder:GetChildren()) do if v.Player.Text == Name then isOnLeaderboard = true break end end if Coins and isOnLeaderboard == false then local newLBFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone() newLBFrame.Player.Text = Name newLBFrame.Coins.Text = Coins newLBFrame.Position = UDim2.new(0, 0, newLBFrame.Position.Y.scaale + (.08 * #game.Workspace.Leaderboard.SurfaceGui.Holder:GetChildren()), 0) newLBFrame.Parent = game.Workspace.Leaderboard.SurfaceGui.Holder end end end) if not success then print(errorMessage) end end while true do for _, Player in pairs(game.Players:GetPlayers()) do Coins:SetAsync(Player.userId, Player.leaderstats.Coins.Value) end for _, frame in pairs(game.Workspace.Leaderboard.SurfaceGui.Holder:GetChildren()) do frame:Destroy() end updateLeaderboard() print("Updated LB") wait(10) end
Here is what the Roblox Studio's console, output or whatever says after I start playing then stopped
**14:58:55.711 Legit Parkour @ 30 Apr 2021 14:58 auto-recovery file was created - Studio - C:/Users/Kasutaja/Documents/ROBLOX/AutoSaves
14:59:04.829 Infinite yield possible on 'ReplicatedStorage:WaitForChild("LeaderboardFrame")' - Studio 14:59:04.829 Stack Begin - Studio 14:59:04.829 Script 'ServerScriptService.LeaderbOard', Line 20 - Studio - LeaderbOard:20 14:59:04.829 Script 'ServerScriptService.LeaderbOard', Line 5 - function updateLeaderboard - Studio - LeaderbOard:5 14:59:04.829 Script 'ServerScriptService.LeaderbOard', Line 43 - Studio - LeaderbOard:43 14:59:04.829 Stack End - Studio 15:00:10.887 The Parent property of
is locked, current parent: NULL, new parent ReplicatedFirst - Studio 15:00:10.888 Stack Begin - Studio 15:00:10.888 Script 'Model.MainModule', Line 20 - Studio 15:00:10.888 Stack End - Studio 15:00:10.848 Disconnect from ::ffff:127.0.0.1|61122 - Studio**
Thank you!
First of all WaitForChild requires a time value.
Infinite yield possible on
basically means it doesn't know when to stop waiting for a child.
heres how it should look
part:WaitForChild("LeaderboardFrame", 10)
this would wait for 10 seconds before terminating.
The Parent property of ? is locked, current parent: NULL, new parent ReplicatedFirst
This was actually a completely new error to me, turns out you attempted to set the parent of a destroyed object.
Something like this
local destroyee = Instance.new("Part", workspace) destroyee:Destroy() destroyee.Parent = game.ReplicatedStorage
Basically destroy sets the parent of an instance to nil, luau's way of deleting data, and locks it. As such you get this error when trying to index the parent parameter.
The fix for this is avoiding setting the parent of a destroyed instance.
Addendum: By Console I presume you mean Developer Console, from what I remember doesn't report errors and is just for running code or moderation in a live game. The output in Studio should be the end all be all for reporting errors. You can also use LogService as a reliable way to get errors in a live game.