Attempted to index nil with CFrame

Hey everyone.

I am working on a meteor/asteroid rain system and I am having this error;

Here is the segment of the script that the error is coming from;


The line in blue is the one with the error.

Does anyone know why this is happening?

sorry for the low quality images, don’t know why it looks so bad lol

I think you confused how to form CFrame.new, read the Understanding CFrames article that should help.

(or use CFrame.Angles)

The issue is that you’re defining RandomMeteor as math.random(1, #Meteors), so RandomMeteor is a number, not a BasePart.

Assuming you’re just trying to fetch a random meteor from the Meteors array, you should change the following:

- local RandomMeteor = math.random(1, #Meteors)
+ local RandomMeteor = Meteors[math.random(1, #Meteors)]
1 Like

To be clear, im only attempting to make the asteroids spawn, not cframe them to the ground

not sure if you knew that just making sure

Thanks, Ill try that real quick, ill let you know if it works

1 Like

Then if thats the case im not sure why you’re using CFrame to begin with.

Thanks! It worked. At first it didn’t, because im stupid and forgot to parent the asteroids to workspace. Thanks for the help

1 Like