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

Why is this not working?

Asked by 9 years ago
local O = script.Parent.Owner.Value
local P = game.Players:FindFirstChild(O)
while true do
    if P.leaderstats then
        P.leaderstats.Cash.Value = script.Parent.Owner.Money.Value
    end
    wait()
end

Error code in output: Workspace.Tycoon.CashHandlerScript:6: attempt to index local 'P' (a nil value)

0
Your code is perfectly fine, just ther was no player matching the Owner's value. Goulstem 8144 — 9y
0
No, I found the answer, It's because i put the ".Value' in line 1 what i needed to do what put it in line 2 like :FindFirstChild(O.Value) CoffeeMesh 5 — 9y

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

As Goulstem already stated, there is nothing wrong with the script at all. Make sure your other scripts are correct, and that the value is there in the first place.


I'd suggest adding in this before defining the variable:

repeat wait() until script.Parent.Owner.Value

That'd help make sure that there is a value in there before the script tries going through the rest of your code.


Anyways, hope I helped a bit, and if you have any questions or problems, please leave a comment below :P

0
Or use `:WaitForChild()`. woodengop 1134 — 9y
Ad

Answer this question