Adding a leaderstat doesn't work if not in the main script

When another script that already made the leaderstat, I can’t add more to the leaderstat in a different script.
It already makes the starter leaderstats with

      local stats = Instance.new("IntValue")
stats.Name = "leaderstats"

	local kills = Instance.new("IntValue")
	kills.Name = "KOs"
	kills.Value = 0

	local deaths = Instance.new("IntValue")
	deaths.Name = "Wipeouts"
	deaths.Value = 0
	
	local damage = Instance.new("IntValue")
	damage.Name = "Damage"
	damage.Value = 0
	
	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Value = 0
	
	stats.Parent = newPlayer
	kills.Parent = stats
	deaths.Parent = stats
	damage.Parent = stats
	wins.Parent = stats

but then if I use

 local newstat = Instance.new("IntValue")
newstat.Name = "Points earned"
newstat.Value = 6 -- lets say I got 6 points
newstat.Parent = game.Players.moo1210.leaderstats

in a different script it doesn’t work. Example:

Is there something I’m doing wrong?

It may be because the leaderstats folder doesn’t exist by the time the 2nd script runs. Try using WaitForChild instead. May also be because your character doesn’t exist at the time either. Either way, you must wait for the Player to load. Try looking through the error messages in your Output window to see what’s up with your code.

4 Likes

@Qxest

That didn’t fix it.

I already checked before posting this, there is no error, it adds the leaderstat but the leaderboard doesn’t display it, as the video I posted shows.

Show the code you tried. I very much so see an error here:
image

@Qxest That error doesn’t effect the leaderstats at all, that error that i ingored for a reason because it only saves the wins and doesn’t effect leaderstats all, but if I fix this error (i know it won’t fix it), I run the script to add the leaderstat, still doesn’t work after fixing the error.
The code that isn’t working is

    local leaderstats = 
    game.Players.moo1210:WaitForChild("leaderstats")
    local newstat = Instance.new("IntValue")
    newstat.Name = "Points earned"
    newstat.Value = 6 -- lets say I got 6 points
    newstat.Parent = leaderstats

Please don’t ignore errors for they break scripts. Check this out:

print("I think I am cool")
wiat(5)
print("No, I'm quite cool")

The first line of code will run but once the “wiat” point is reached the whole script breaks meaning nothing after that line runs. The script has now “exited.”

The problem with the code you just posted is moo1210 is not a valid member of game.Players at the time script runs. You’d have to run WaitForChild on moo1210.

you’re probably using a local script. Local scripts don’t work. Use a server script

You didn’t watch the video, the script isn’t enabled intill I uncheck the box, and also it was in a pcall in case the player leaves at the perfect time somehow, pcalls don’t exit scripts, they just print the error. I added the pcall to prevent the whole leaderboard is breaking. You also completed ignored the picture I sent and the other info I also sent with it. It IS adding the intvalue into the user “moo1210” it isn’t displaying it on normal roblox leaderboard.

You also ignored the video, I very clearly added a server script, even if it was a local script it would still display it on the leaderboard on only moo1210’s clients. I added the screenshots and video for a reason, because the very well help understanding this issue.

my quality was low, so I couldn’t see. Now I see, the script is disabled, try enabling it BEFORE it starts
Edit: try debugging it by testing if it’s nil, if it’s not, then you shouldn’t worry about it

This also isn’t the problem. I’ve been tinkering around in studio and quickly came to the conclusion that the max to show for leaderstats is 4 values. Exceeding that amount causes the leaderstats to NOT show them on the leaderboard.

This has to do with that the stats shouldn’t be taking in the whole screen. A simple sollution to this is to make a custom leaderboard.

1 Like

You don’t even need to test for this. This is the case as stated right in the leaderboard CoreScript.

Searching is golden. You are definitely right though; has nothing to do with screen space or code not running or anything. There is native support for added and removed leaderstats. It’s the fact that there’s a maximum for the display.

is it possible to download the playerlist and change the value?

It is. On the file, just hit raw, then in order:

  • Ctrl + A
  • Ctrl + C

Then in the actual script of course,

  • Ctrl + V

There are a few things you will need to review in the script to ensure that the change works, as I do not believe that only changing the maximum number will suffice as far as adding more leaderstats to the display goes:

  • Disabling the CoreGui leaderboard
  • Removing all cases of internal function use (functions that developers can’t use)
  • Reorganising other data as necessary

My personal take, if you value it any: both forking this script and creating your leaderboard are far more trouble than they are actually worth. It would be better if you only display stats that you think are important and keep the rest off the leaderboard. For example I wouldn’t display a user’s damage, wins or points. Keeping a user’s UI clean and only showing stats I think they and other users want to see are the best routes for UX.

Ultimately that’s your call though.

4 Likes