How do i get the cframe of a models primary part?

I cant find anything about it, only serprimarypartcframe

Couldn’t you just do Model.PrimaryPart.CFrame?

no, it just says “attempt to index nil with CFrame”

This means that you don’t have a PrimaryPart set. You need a primary part set for it to work.

Maybe primary part does exist but doesn’t exist yet, do :WaitForChild maybe.

but in the same script, i move the primary part without one set…

so i can move it but not rotate it and i need to know how to rotate it

PrimaryPart is a property, not an instance. You can’t wait for properties, only instances.

so how would i set the roation of it

It would be helpful if you could share some of your code, and explain what you are trying to achieve.

local roomsfolder = game.Workspace:WaitForChild("Rooms")
local largeroomsfolder = game.Workspace:WaitForChild("LargeRooms")
local roomspawns = game.Workspace:WaitForChild("RoomSpawns")
local addedrooms = game.Workspace:WaitForChild("AddedRooms")

local roomsfolderchildren = roomsfolder:GetChildren()
local largeroomsfolderchildren = largeroomsfolder:GetChildren()
local randomroom = nil

for _, v in pairs(roomspawns:GetChildren()) do
	v.Transparency = 1
	if v.Name == "RoomSpawnLarge" then
		randomroom = largeroomsfolderchildren[math.random(1, #largeroomsfolderchildren)]
		local ClonedRoom = randomroom:Clone()
		ClonedRoom.Parent = addedrooms
		ClonedRoom:MoveTo(v.Position)
		
		local rotation = v.CFrame:inverse() * ClonedRoom.PrimaryPart.CFrame

		v.CFrame = v.CFrame * CFrame.Angles(0,math.rad(90), 0)
		ClonedRoom.SetPrimaryPartCFrame = v.CFrame * rotation
	else
		randomroom = roomsfolderchildren[math.random(1, #roomsfolderchildren)]
		local ClonedRoom = randomroom:Clone()
		ClonedRoom.Parent = addedrooms
		ClonedRoom:MoveTo(v.Position)
	end
end

What this is doing is basically cloning a random model,. then putting it in a selected popstition.

I have a bigger spawn position that is not square, and sometimes needs to have the model rotated to match its rotation

Okay, you can either set the PrimaryPart for your room so that you can utilize the property, or you can try using GetPivot method on the room model.

ok ill try setting the primary part. Thanks!

Now ts saying “Setprimarypartcframe is not a valid member”

What do i replace it with to substitute it

You are trying to use SetPrimaryPartCFrame as a property.

model.SetPrimaryPartCFrame = CFrame.identity

But it is a method, so you have to call it.

model:SetPrimaryPartCFrame(CFrame.identity)

Additionally, it is a deprecated method. You should use PivotTo and GetPivot methods instead.

model:PivotTo(CFrame.identity)
1 Like

so how would i rotate the model to match the parts rotation?

PivotTo takes a CFrame like provided in my example. In your code specifically, the call would look like this:

ClonedRoom:PivotTo(v.CFrame * rotation)

But the primarypart is a part, so just wait for the actual part. (The instance type)

now im not getting errors, but the rooms are not rotating…

The error stated that the Model didn’t have a PrimaryPart, so how are you going to wait a for a BasePart that isn’t set? Also, you can’t wait for instance like that, as you need its parent, and know its name, which may be duplicate since names aren’t unique, you won’t be able to wait for the right part.

i thoughthe set itim sorry im sorry

1 Like