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

leaderstats not being found in Player?

Asked by
Nixvoid 12
6 years ago

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

0
leaderstats.Parent = game.Players.LocalPlayer BFFperson32 -6 — 6y
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. Nixvoid 12 — 6y

2 answers

Log in to vote
0
Answered by
yyyyyy09 246 Moderation Voter
6 years ago
Edited 6 years ago

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")
1
Thank you, I understand what you mean. You have been very helpful and have sorted out my issue. Nixvoid 12 — 6y
0
You're very welcome yyyyyy09 246 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)

Answer this question