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

Why does it say this variable is nil?

Asked by 9 years ago

so the variable, coin1c, is nil. on line 43 (coin1c.Parent = script.Parent) why is this?

01local CoinDropping = false
02 
03    if CoinDropping == false then
04        CoinDropping = true
05    if script.Parent:FindFirstChild("Coin1") then
06        coin1c = script.Parent.Coin1:Clone()
07        script.Parent.Coin1.CFrame = script.Parent.PointL.CFrame
08        script.Parent.CoinBPos:Clone().Parent = script.Parent.Coin1
09        script.Parent.CoinMover:Clone().Parent = script.Parent.Coin1
10        script.Parent.Button.ClickDetector.MouseClick:connect(function()
11            script.Parent.Coin1.CoinBPos:Destroy()
12        end)
13        CoinDropping = false
14    elseif script.Parent:FindFirstChild("Coin2") then
15        coin2c = script.Parent.Coin2:Clone()
View all 51 lines...
0
You have not defined coin1c in that section. TheDeadlyPanther 2460 — 9y
0
but i made it global to the whole script havent i? bubbaman73 143 — 9y
0
How could i fix this? bubbaman73 143 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I think you might want to WaitForChild them at the beginning of the script. Plus, Use Individual If(s) If I'm correct, Your script, it's like, First if checks, no, second, no, third no, after all that, it goes to the else statement, Sadly at the else statement, You're setting the parents without a variable defined, An "If" with an "ElseIf" and "Else" It would only select "One" To do, First to Bottom. First until 1 before bottom, fails, and at the bottom There's an Else, it would (ONLY) go with that else So it means that the variable isn't even Declared by your Ifs EDIT: This might be what i would do for a fix

01local CoinDropping = false
02 
03if CoinDropping == false then
04  CoinDropping = true
05  if script.Parent:FindFirstChild("Coin1") then
06    coin1c = script.Parent.Coin1:Clone()
07    script.Parent.Coin1.CFrame = script.Parent.PointL.CFrame
08    script.Parent.CoinBPos:Clone().Parent = script.Parent.Coin1
09    script.Parent.CoinMover:Clone().Parent = script.Parent.Coin1
10    script.Parent.Button.ClickDetector.MouseClick:connect(function()
11    script.Parent.Coin1.CoinBPos:Destroy()
12    end)
13    CoinDropping = false
14  end
15  if script.Parent:FindFirstChild("Coin2") then
View all 53 lines...
Ad

Answer this question