Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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:

wait()
while true do
	wait()
	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'
		script.Parent:Destroy()
	else
		script.Parent.Position = script.Parent.Parent.TextButton.Position
	end
end

2 comments

0

try changing position to UDim2

0

@mikey2019d UDim2 is not a valid member of ImageLabel

2 answers

✓ Accepted answer

Try this out.

local MapButton = script:FindFirstAncestor("MapButton")
local ImageLabel = MapButton:FindFirstChildOfClass("ImageLabel")

while true do
	wait()
	if ImageLabel.Position == UDim2.new(1,0,.907,0) then
		ImageLabel:Destroy()
		break
	else
		ImageLabel.Position = MapButton.TextButton.Position
	end
end

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.