Attempt to index nil with 'Position'

Hello! I need help on an error I havent gotten before it states what the title says above, the certain line in question is lua Storm.PrimaryPart.Position = Storm.PrimaryPart.Position + Vector3.new(dx, 0, dy) I provided the function, I want the storm to move based on the windDirection and time. The windspeed is reserved for tornadoes. The wind direction determines what angle the storm moves at. Thank you!

local StormModule = {}

function StormModule.Move(WindDirection, WindSpeed, Time)
	local Storm = workspace.Storm.Supercell
	local WindDirectionDegrees = math.rad(WindDirection or 45)  -- Convert to radians, default to 45 degrees if WindDirection is nil
	local Time = Time or 5  -- Use provided Time or default to 5

	local function ActivateStorm()
		-- Calculate displacement based on wind speed and time
		local dx = Time * math.cos(WindDirectionDegrees)
		local dy = Time * math.sin(WindDirectionDegrees)

		-- Update the position of the storm object
		Storm.PrimaryPart.Position = Storm.PrimaryPart.Position + Vector3.new(dx, 0, dy)
	end

	ActivateStorm()
end

return StormModule
1 Like

Well, does the storm have a PrimaryPart?

1 Like

no, I dont really know why i even added primarypart. I forgot you had to assign it to something, but what would i assign it to?

Here’s the documentation on PrimaryPart. It’s essentially the anchor point for the model, the part of which all other parts of said model will pivot around if physics acts upon them. You’d probably want to set this to the largest part of the model, or a point in the center, or a part representing an axis.

This.

Otherwise, consider using Model:MoveTo(vector3) or Model:PivotTo(cFrame).

1 Like

so I could put it in the center of the supercell? or i could just consume the entire supercell in the part

Right. I don’t know exactly what your model looks like or how you want it to move, so I’d suggest experimenting with different part sizes to find which works best for you. I think a large part centered to it would likely work best though.

I tried with a large primarypart consuming the supercell which is a model which is a bunch of parts and it says the same error

It doesn’t really matter. You can do either, but probably make it take up the entire thing. You can also generate it through the console:

Edit: By console I mean the lil command bar you can open up in studio, just paste it in, press enter and you’re gucci

local model = workspace.Storm.Supercell
local part = Instance.new("BasePart", model)
part.Name = "PrimaryPart"
local cf, size = model:GetBoundingBox()
part.Size = size
part.CFrame = orientation
model.PrimaryPart = part

That’s weird. You’re sure you’re setting the PrimaryPart property of the model? I’m not certain why you’d be getting the same error otherwise.

this passed all of my bug checks, which is good, but it doesnt move, is it because primary part is anchored perhaps? or something else

What exactly does your Explorer look like? Is it something like this?

Workspace
    Storm (Model)
        Supercell (BasePart)

In this case, you want to be referencing the workspace.Storm, not workspace.Storm.Supercell.

image

Ngl, you probably wanna use MoveTo() in this case. Your current code will only move the primary part and nothing else. If you did wanted to move everything, you would use CFrame movement, but then you would have to rig it. So just do Storm:MoveTo(Storm.PrimaryPart.Positon + Vector3.new(dx,0,dy)).

1 Like

This, or a method that doesn’t require a PrimaryPart:

Storm:PivotTo(Storm:GetPivot() + Vector3.new(dx, 0, dy))
1 Like

18:09:53.791 Positon is not a valid member of Part “Workspace.Storm.Supercell.PrimaryPart” - Server - StormModule:23 im sorry guys this is taking way to long but it threw out this error. What I want it to do is in another script directions may change (aka the degrees) and the storm moves in different wind directions intill its timer runs out.

Position, not Positon.

You should probably make a separate thread for the second part.

1 Like

storm moves! just kinda teleports lol

now, I need to figure out how im able to make it repeatedly move and change direction in degrees

Glad to hear that you got it worked out. Though as @OniiSamaUwU suggested, it would probably be best to make a new thread for that and mark this one with a Solution to make it easier for others having a similar issue to find a fix.

Happy to help, though! Happy suffering.

1 Like