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

error : attempt to index nil with 'Position' how do I fix ?

Asked by 4 years ago
Edited by Leamir 4 years ago

Here is the script (for a pop up)

for i = 1,20 do
    script.Parent.Position = UDim2.new(math.random(20,60)/250,0,math.random(20,60)/250,0)
    script.Parent:TweenSize(UDim2.new(0, 250,0, 250),"Out","Bounce",1,true)
    wait(1.5)
    script.Parent:TweenSize(UDim2.new(0, 250,0, 250),"Out","Linear",0.3,true)
    wait(0.4)
    script.Parent:Destroy()
end

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I'm asuming your error is here: script.Parent.Position = since i don't see any other .Position anywhere else inside the for loop.

You are receiving that error because you destroy the parent object script.Parent:Destroy() at the end of that iteration of the loop, then once it goes to the next number the parent object is not there anymore because it was destroyed

0
oh thanks :) Dinosaur201111 7 — 4y
0
yeah it works changed the script Dinosaur201111 7 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Is the script parented a GuiObject [Frame/ScrollingFrame/ViewportFrame/TextLabel/TextButton/ImageLabel/ImageButton]? If not, parent it to a guiObject!

Answer this question