How can I make a leaderstat?

Hey, so I was wondering how I can make a leaderstat?

Heres the script I’ve tried so far.

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“IntValue”, player)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local part_count = #workspace.Folder:GetChildren()
local PartCounter = Instance.new(“IntValue”, leaderstats)
PartCounter.Name = “Parts”
PartCounter.Parent = leaderstats
PartCounter.Value = part_count
end)

Can someone help? Thanks :slight_smile:

why change #workspace to workspace ??

Oh that’s alright we all do errors sometimes ! :slight_smile:

1 Like
plrEntered = function(plr)
    local ls = Instance.new('IntValue') --Leaderstats
    ls.Parent = plr
    ls.Value = 0
    ls.Name = 'leaderstats'

    local stat = Instance.new('IntValue')
    stat.Name = 'Cash' -- Change to the value you want
    stat.Value = 0 -- Add the starting value
end

game:GetService'Players'.PlayerAdded(plrEntered)

That would be in a SSS, Server Script Service

Credits to: https://stackoverflow.com/questions/4272592/how-do-i-make-a-leaderboard-on-roblox

im not a very good developer but you could simply do

game.Players.PlayerAdded:Connect(plrEntered)

1 Like

How would that be a leaderboard? That only gets the played added… it’s not a leaderboard…

Wait i dont understand what you just told me lol

No, he’s trying to make a leaderboard. So, you need to script the rest that makes the leaderboard and not just

game.Players.PlayerAdded:Connect(plrEntered)

I said you could simply do

game.Players.PlayerAdded:Connect(plrEntered)

instead of

game:GetService’Player’.PlayerAdded(plrEntered)

ok, but i didnt learn that way i guess both would work, never saw a leader board that way, but it’s fine.

1 Like

oh its completly fine and find and btw i dont think game:GetService’Players’ work cause it need ()
so it become : game:GetService(‘Players’)

1 Like

Hello, @hauntedzx try adding a script in ServerScriptService and pasting this in:

game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder",plr) -- Creates a Folder inside the Player Instance
leaderstats.Name = "leaderstats"

local PartCounter = Instance.new("IntValue",leaderstats) -- Creates a new IntValue inside the folder we creates
PartCounter.Name = "Parts"

for i,v in pairs(game.Workspace.Folder:GetChildren()) do -- This loop goes through the items inside the folder

if  v:IsA("Part") then -- Checks if the item inside the folder is a Part
PartCounter.Value = i -- Changes the value if its a Part
end
end
end) 

Hope it helps :slight_smile:

When you give the whole script to someone, I would suggest you explain what the lines does, so they might clear their doubts :slight_smile:

Yep, I added comments to my script so he understands :slight_smile:

Didn’t work :confused: Unfortunately.

The leaderstats thing comes up but it doesn’t tell me the parts number.

leaderstats only show when that are in a Folder named leaderstats
Use this script

game.Players.PlayerAdded:Connect(function(plr)
local Folder = Instance.new(“Folder”)
Folder.Parent = plr
Folder.Name = leaderstats
local Value = Instance.new(“IntValue”)
Value.Parent = Folder
Value.Name = “Your leaderstat name here”
end)

I will work on a way to show the part amount

Wait I have 1 question. Do you want the part amount to save so it will be the same if a player leaves then rejoins?

Did you make sure that there are parts inside the folder?

Hope this helps you!

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local q = Instance.new("Folder", plr)
local w = Instance.new("IntValue", q)

local q.Name = "leaderstats" -- Don't change.
local w.Name = "Parts"

while true do
wait (.01)
w.Value = #workspace.Folder:GetChildren()
end
end)
-- Place in workspace / SSS (server script service)