Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[Help] leaderboard script wont work and wont run?

Asked by 5 years ago

This simple leaderboard script won't work at all and I don't know why, please help.

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "Leaderstats"

    local XP = Instance.new("IntValue", leaderstats)
    XP.Name = "XP"
    XP.Value = 0

end)
0
Debug the code. hiimgoodpack 2009 — 5y
0
Never part instances like that. Take a look at this. :) https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296 ForeverBrown 356 — 5y

5 answers

Log in to vote
0
Answered by
BashGuy10 384 Moderation Voter
5 years ago

Here, the most efficient leaderstats script:

Most of the answers above are not optimized, this one will make your game run smother:

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder") -- The folder and be anything, it can even be a beam or something!
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player -- Dont ever set the parent inside the Instance.new() function, it causes lag!

    local XP = Instance.new("IntValue")
    XP.Name = "XP" -- You dont need to set the value if its going to be 0 at the start of the game.
    XP.Parent = leaderstats

end)
Ad
Log in to vote
0
Answered by 5 years ago

I'm going to assume where you said; "script won't work and won't run" that you expected it to literally show the Roblox leaderboard GUI in the top right corner. Let's start with a couple things:

  1. Ensure that the script that is being used is a server sided Script placed in a place where the script can run; Workspace or ServerScriptService

  2. Next make sure that parent object that stores the stats is a model; roblox will only recognise models named leaderstats in the player to display leaderstats.

It should look like this:

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local XP = Instance.new("IntValue", leaderstats)
    XP.Name = "XP"
    XP.Value = 0

end)

Improvements:

This script can be improved like so:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = Player

    local XP = Instance.new("IntValue")
    XP.Name = "XP"
    XP.Value = 0
    XP.Parent = Player
end)

Notes:

  1. Never use the second argument of Instance.new() as it can cause lag

  2. Always parent last unless you want the player to see the changes

Hope this helped!

Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

Both of the scripts above Wont work, the “leaderstats” has to me named leaderstats or it won’t work, and the parent argument is included in Instance.new()


game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) -- Instance.new("Folder",player) automatically sets the parent to “player” leaderstats.Name = "leaderstats" -- has to be named “leaderstats” local XP = Instance.new("IntValue", leaderstats) -- Use “IntValue” for whole numbers, use “NumberValue” for numbers with decimals XP.Name = "XP" XP.Value = 0 end)
0
Dont ever set the parent inside the Instance.new() function, it causes lag! BashGuy10 384 — 5y
Log in to vote
-1
Answered by
Gingerely 245 Moderation Voter
5 years ago

leaderstats L is capital it should be lower case.

Log in to vote
-2
Answered by 5 years ago

It's not a folder, it's a model. Recently did this.

game.Players.PlayerAdded:Connect(function(p)
 local StatsParent = Instance.new("Model", p)
 StatsParent.Name = "leaderstats"

 local NewStat = Instance.new("IntValue", StatsParent)
 NewStat.Name = "XP"
end)
0
IT DOESN'T HAVE TO BE A MODEL BashGuy10 384 — 5y
0
you can have it as what ever you want, it can even be a part for gods sake BashGuy10 384 — 5y
0
This makes my mind go crazy, people thinking the leaderstats container has to be a frecking model BashGuy10 384 — 5y
0
lmao and some people say you did not set its parent when the main problem is, leaderstat's L is capital lol thats why it does not work. :) Gingerely 245 — 5y

Answer this question