Attempted to Index nil with position?

  1. What do you want to achieve? Keep it simple and clear!
    Make something, known as smilers, go to a CFrame position with parts.

  2. What is the issue? Include screenshots / videos if possible!
    I keep getting this:
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    There are no solutions on this, i even checked the tutorial that teached how to do this.
    Also here is the script:

attacks[1] = function()
	local losers = {}
	for i = 1,2 do
		local smiler = game.ServerStorage.Monster:Clone()
		table.insert(losers, smiler)
		smiler.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.MonsterWaypoints:FindFirstChild("Part"..i).Position + Vector3.new(0,3,0))
		smiler.Parent = workspace
	end
	task.wait(10)
	for i,v in pairs(losers) do
		v:Destroy()
	end
end

The tutorial’s code (that somehow worked):

Is there a solution for this? There isn’t any fix for this on YouTube or anything.

This is the only part in the code that actually uses Position:

game.Workspace.MonsterWaypoints:FindFirstChild("Part"..i).Position

You are sure that Part exist in game.Workspace when trying to get its position?

in the monster waypoints folder in Workspace, yes

A part inside that folder called maybe “Part1”, “Part2” etc?

Cause the output is telling you that its not possible to get .Position from that part, possibly doesnt exist, or the name is not correct, or one of the parts are missing

just for testing run this code in the command bar or inside your script:

print(game.Workspace.MonsterWaypoints:GetChildren())

I just found out i didnt name the first part part1.

1 Like

Yup, thats the issue, cause the output was saying it was not possible to get Position from something that is nil

Well it got fixed, thanks! I didn’t know that parts unnumbered were nil.

Nope, a part can be called whatever you wish, that was not the problem.

The issue was, that you are running a loop twice, each time the function repeats its looking for a part in that folder, a part called “Part” plus the number of the iteration (repetition), 1, 2, 3 etc

That means per each repeat that number increase, and the parts in folder should be named exactly as what the loop is looking for “Part1”, “Part2”.

Actually, I would try to avoid doing it in that way…

Lets say, you create a loop that repeats 50 times, then you gotta create 50 parts and rename them Part1, Part2, etc until 50…

Would be better to run the loop based on the parts that exist in the folder.
The loop will repeat only once par part in the folder. Something like:

for repeats, part in pairs(game.Workspace.Folder:GetChildren()) do
    print(part.Position)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.