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