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

Why is this leaderboard not being made?

Asked by
Klamman 220 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by 8 years ago

~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

Ad
Log in to vote
0
Answered by 8 years ago

leaderstats has to also be an int value.

    local leaderstats = Instance.new("IntValue")
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. Klamman 220 — 8y
0
'leaderstats has to also be an int value.' ConnorVIII 448 — 8y
Log in to vote
0
Answered by 8 years ago

Hmm. Maybe it's because it's in there. Or maybe because it's a LocalScript.

I tried pasting it in the workspace, and it's a Normal Script. it works. Then I tried with a local, it doesn't work.

Use a normal script.

Answer this question