Hi guys ive made this little leaderstats script and i cant figure out why it doesnt work, ive compared it to other leaderstats script and its seem that nothing is wrong
function OnPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "LeaderStats" local Cash = Instance.new("IntValue") Cash.Name = "Money" Cash.Value = 500 Cash.Parent = stats stats.Parent = newPlayer end game.Players.ChildAdded:Connect(OnPlayerEntered)
It might not be the best idea to compare the code with older scripts as things change like ChildAdded is no longer used for when a player joins as we now have the event PlayerAdded
For leaderstats to work you need a child named leaderstats
or else it will not work and it does not depend on what instance it is. I would probably use a folder but thats just me.
You did correctly parent the new instances as they should be setup first then parented.
For this to work you only need to change the name but it better to use the correct event.
-- using the player added event will only run for player not ChildAdded which runs for anything added to the Players service game.Players.PlayerAdded:Connect(function(plr) local ls = Instance.new("Folder") ls.Name = "leaderstats" -- must be named this to work local cash = Instance.new("IntValue") cash.Name = "Money" cash.Value = 500 cash.Parent = ls ls.Parent = plr end)
Hope this helps.