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

Are leaderboards broken?

Asked by 9 years ago

I looked at the wiki for the leaderboards. When I did a play solo nothing happened. This is the one from the wiki.

game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("Model", player)
     leaderstats.Name = "leaderstats"

     local money = Instance.new("IntValue", leaderstats) 
     money.Name = "Money" 
     money.Value = 0
 end)

I changed the Instance.new("Model", player) to Instance.new("IntValue", player) but still nothing happened. Also I changed it to a global script and a local.

3 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

Well, first make sure this is a server script inside of Workspace or ServerScriptService.

Second, make sure it's not disabled.

I've always used IntValues for the leaderstats object, but since the wiki says Models are fine I'll assume that's true.

Add print()'s to your script to try to find where the problem is.

In the past, PlayerAdded events have not fired in PlaySolo. I thought Roblox fixed this, but try starting a server and seeing what happens.

Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

When testing in Solo, the player usually arrives before Scripts start running.

This means when you get to the PlayerAdded connection, it's too late for you to capture the first player joining.

The simplest way to fix this is something along the following:

function newPlayer(player)
    local leaderstats = Instance.new("IntValue", player)
    leaderstats.Name = "leaderstats"
    local money = Instance.new("IntValue", leaderstats) 
    money.Name = "Money" 
    money.Value = 0
end

game.Players.PlayerAdded:connect( newPlayer )
-- For all future players, use the event

-- For all the players already joined, let's just *say* they joined
-- just now:
for _, player in pairs(game.Players:GetPlayers() ) do
    newPlayer( player )
end


Note that the IntValue for leaderstats is the canonically correct instance (not Model), though I'm unsure whether or not other types of classes will work.

Log in to vote
-3
Answered by 9 years ago

Try to use IntValue for leaderstats and add wait after PlayerAdded.

game.Players.PlayerAdded:connect(function(player)
wait(.5)
     local leaderstats = Instance.new("IntValue", player)
     leaderstats.Name = "leaderstats"

     local money = Instance.new("IntValue", leaderstats) 
     money.Name = "Money" 
     money.Value = 0
 end)

Answer this question