Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this leaderboard not being made?

So, I'm trying to create a leaderboard through instantiation, but it doesn't seem to be working. Does anyone know what I'm doing incorrectly here? This is a local script being kept in StarterPlayerScripts. Here's my code:

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("Model")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local leaflets = Instance.new("IntValue")
	leaflets.Name = "Leaflets"
	leaflets.Value = 0
	leaflets.Parent = leaderstats
end)

Thanks in advance.

3 answers

✓ Accepted answer

~SOLUTION ~


player = game.Players.LocalPlayer

local Players = game:GetService("Players")

function OnPlayerAdded(plr)
	print("This is just a test")
	  local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local leaflets = Instance.new("IntValue")
    leaflets.Name = "Leaflets"
    leaflets.Value = 0
    leaflets.Parent = leaderstats
end


for _,v in pairs(Players:GetPlayers()) do
	OnPlayerAdded(v)
end

game.Players.PlayerAdded:connect(OnPlayerAdded)

~SOLUTION ~

So... How I fixed it... Technically when you are using a LocalScript, and you try to use PlayerAdded Event, the Character has still not loaded when you start the simulation or when they enter the game, that's why you have to get the service, and then later on call it with a in pairs loop.

Leaderboard works like a charm ;)!

Link for more specific information about it.

http://wiki.roblox.com/index.php?title=API:Class/Players/PlayerAdded

leaderstats has to also be an int value.

    local leaderstats = Instance.new("IntValue")

2 comments

0

The wiki says that the leaderstats value should be either a model or a folder, and a value object may not work. After some testing, this solution doesn't seem to work, either.

0

'leaderstats has to also be an int value.'

This discussion is preserved as it was. New answers, comments, and votes are closed.