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

[SOLVED] How do I fix this error, "attempt to index nil with 'Position'"?

Asked by 4 years ago
Edited 4 years ago

Information:

THIS QUESTION HAS BEEN SOLVED

  • I am getting an error on line 4. The error is "Players.Dave_Robertson.PlayerGui.MapButton.ImageLabel.LocalScript:4: attempt to index nil with 'Position'"
  • I am trying to do a if then script
  • The parent of the script is ImageLabel
  • The script is a LocalScript
  • GUI: https://ibb.co/bXV2ZYD
  • StarterGui: https://ibb.co/yy44kZG

Script:

1wait()
2while true do
3    wait()
4    if script.Parent.Position == UDim2.new(1,0,0.907,0) then -- Players.Dave_Robertson.PlayerGui.MapButton.ImageLabel.LocalScript:4: attempt to index nil with 'Position'
5        script.Parent:Destroy()
6    else
7        script.Parent.Position = script.Parent.Parent.TextButton.Position
8    end
9end
0
try changing position to UDim2 mikey2019d 43 — 4y
0
@mikey2019d UDim2 is not a valid member of ImageLabel Dave_Robertson 42 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

Try this out.

01local MapButton = script:FindFirstAncestor("MapButton")
02local ImageLabel = MapButton:FindFirstChildOfClass("ImageLabel")
03 
04while true do
05    wait()
06    if ImageLabel.Position == UDim2.new(1,0,.907,0) then
07        ImageLabel:Destroy()
08        break
09    else
10        ImageLabel.Position = MapButton.TextButton.Position
11    end
12end
Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
4 years ago

You have an unnecessary while true do loop here. The loop will destroy your ImageLabel after first or second iteration. Hence the error. Unfortunately it is unclear to me what you are trying to achieve, so I can't really help you more.

Answer this question