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 or ServerScriptService
- 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!
2 comments
Debug the code.
Never part instances like that. Take a look at this. :) https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296