I’m making a leaderboard to update and sync with leaderstats so I am trying to define the leaderstats.
The issue is that its giving me an error saying my code tried to index nothing with FindFirstChild but the code leads straight to the object.
function Update()
local frames = workspace.Leaderboard.SurfaceGui.ScrollingFrame:GetChildren()
for v,v in pairs(frames) do
if v:IsA("Frame") then
v:Destroy()
end
end
local leaderstats = game.Players.LocalPlayer:FindFirstChild("leaderstats")
local donation = leaderstats and leaderstats:FindFirstChild("Donation")
for _,plr in next, game:GetService("Players"):GetPlayers() do
pcall(function()
lbData:UpdateAsync(plr.UserId, function() return plr:FindFirstChild("leaderstats"):WaitForChild("Donation").Value end)
end)
end
it’s this line right? local leaderstats = game.Players.LocalPlayer:FindFirstChild("leaderstats")
I think the issue is that game.Players.LocalPlayer is nil since you seem to be using a script instead of a local script.
Either remove those lines or do that inside that loop and replace game.Players.LocalPlayer with plr
As everyone else mentioned, it’s cause you’re using LocalPlayer in a server script, you don’t use those for anything, so I think you can just remove them
function Update()
local frames = workspace.Leaderboard.SurfaceGui.ScrollingFrame:GetChildren()
for v,v in pairs(frames) do
if v:IsA("Frame") then
v:Destroy()
end
end
for _,plr in next, game:GetService("Players"):GetPlayers() do
pcall(function()
lbData:UpdateAsync(plr.UserId, function() return plr:FindFirstChild("leaderstats"):WaitForChild("Donation").Value end)
end)
end
You suggested using a local script but he’s obviously using data stores which would not work there.
Tho removing those lines completely is also not a great solution, if OP could give us more info we could help.