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

Apparently it say's i'm trying to index a nil val, so what did I do wrong?

So, I wanted to try out something where a brick moves to different points with a for loop.

local current = 1 
local prts = script.Parent.Model:GetChildren()
local ran = game.Workspace.Part
ran.Material = Enum.Material.Neon
ran.BrickColor = BrickColor.new("Bright red")
ran.Position = prts[1].Position
ran.Orientation = prts[1].Orientation 
canR = true

game.Workspace.clik.ClickDetector.MouseClick:Connect(function()
print("starting")
	if canR then
		canR = false
		for i = 0,#prts,1 do 
		wait(.1)
		current = current + 1
			ran.CFrame = prts[current].CFrame
			ran.Orientation = prts[current].Orientation
				if current == 4 then 
					ran.BrickColor = BrickColor.new("Bright green")
						print("Done")
					ran.Position = prts[1].Position
					ran.Orientation = prts[1].Orientation 
					wait(1)
					ran.BrickColor = BrickColor.new("Bright red")
					canR = true
				end	
		end
	end
end)

And I got the error

14:21:04.033 - Workspace.Model.Script:17: attempt to index field '?' (a nil value)

1 answer

The local prts is a model, therefore it doesn't have a CFrame

4 comments

0

Actually, just realised the [current], but make sure that isn't a model either

0

Sorry for the mistake, had a similar problem just now, hence me jumping to conclusions without reading the whole thing. If it really won't work, then try having a folder of Vector3 Values and just move it through those.

0

Wait, I think I just got it. Could it be becuase, I didn't set current back to 1 again?

0

This should be a comment.

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