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

leaderstats not being found in Player?

I've scripted a moneyGiver, moneySpend, itemDropper and leaderboardSystem. . They all have their own custom functions as: moneyGiver(), moneySpend(), itemDropper() and leaderboardSystem().

Occasionally, for some reason the leaderboard can be found in the Player and sometimes it isn't found. When I test the game in a server, the moneyGiver works completely fine. So does the itemDropper, and so does the leaderboard. However, when I click the moneySpend pad, it is supposed to deduct cash. Yet, it doesn't and says that the leaderstats cannot be found inside the Player. I have no idea how I would be able to fix this.

The screenshot with the error and code can be found here: http://prntscr.com/jqz3hb

Thank you. :)

~Nixvoid

2 comments

0

leaderstats.Parent = game.Players.LocalPlayer

0

I don't even need to try that to know that it cannot be used. LocalPlayer cannot be used to find the player. It only works for the client, rather than the server since these are server side scripts.

2 answers

✓ Accepted answer

Your leaderboard system is loading after the moneySpend script has run

local stats = game.Players:FindFirstChildOfClass("Player"):WaitForChild("leaderstats")

local cash = game.Players:FindFirstChildOfClass("Player"):WaitForChild("leaderstats"):WaitForChild("Cash")

2 comments

1

Thank you, I understand what you mean. You have been very helpful and have sorted out my issue.

0

You're very welcome

game.Players.PlayerAdded:connect(function() local stats = Instance.new("Model") stats.Name = "leaderstats"******** local money = Instance.new("NumberValue") money.Parent = stats stats.Parent = game.Players.LocalPlayer end)

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