Since I started programming roblox lua I always had this problem and it's time to fix it. I tried it different ways: 1.
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local playerGui = player:WaitForChild("PlayerGui")
end)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local playerGui = player:FindFirstChild("PlayerGui")
end)
game.Players.PlayerAdded:Connect(function(player)
wait(5)
local leaderstats = player:WaitForChild("leaderstats")
local playerGui = player:WaitForChild("PlayerGui")
end)
game.Players.PlayerAdded:Connect(function(player)
wait(5)
local leaderstats = player:FindFirstChild("leaderstats")
local playerGui = player:FindFirstChild("PlayerGui")
end)
I don't have more ideas on how to do it, so I depend on whoever answers my question. Thanks.

9 comments
I think that is literally the only way
it doesn't work xd
Is there a script anywhere that adds the leaderstats in the Player?
@nampha666yes
Your first option is the best.
yes but it doesn't work
You cannot get gui's from server scripts.
Program client sided.. send remotes to the server..
rule 1: never trust client