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)
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)
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:
Ensure that the script that is being used is a server sided
Script
placed in a place where the script can run;Workspace
orServerScriptService
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:
Never use the second argument of Instance.new() as it can cause lag
Always parent last unless you want the player to see the changes
Hope this helped!
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)
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)