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.
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.
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.
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)