Leaderboard Help

So I’m pretty new to this scripting stuff, and I decided that off memory I would try and make a leaderboard script. I have written this and it seems to output nothing. Any help would be greatly appreciated.

local function onPlayerJoin(player)

local leaderstats = Instance.new(“Folder”)

local player = game.Players.LocalPlayer

leaderstats.Parent = player

local gold = Instance.new(“IntValue”)

gold.Value = 0

gold.Parent = leaderstats

game.Players.PlayerAdded:Connect(onPlayerJoin)

end

Two mistakes here.

LocalPlayer is nil to the server. If you asked your teacher to get the local student, who would your teacher pick? A student/player cannot be picked at random.

You already have the player parameter, so why try reinventing the wheel?

Second mistake is you don’t name the leaderstats to "leaderstats". The folder itselfs needs to be named that, not the variable pointing to it. Third mistake is you are trying to connect within the listener function itself.

-- Just using my own styles, you can use your own too
local function on_player_join(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local gold = Instance.new("IntValue")
    gold.Name = "Gold"
    gold.Value = 0
    gold.Parent = leaderstats
end

game:GetService("Players").PlayerAdded:Connect(on_player_join)

Damn thats kinda confusing. Thank you so much for the help!