Rotation not working for models

Basically, in a code that i have for spawning props around a map in an area that is preset using a base part, its not setting the rotation for the part no matter what i try.

INFO:
the part does have a primary part and every base part in the model is welded using a weld constraint to the main part, every part is unanchored except for the main part. The positioning works fine but the rotation doesn’t. if u need any other information, lmk

local function createProp(spawnLocation, grass)`
local area = spawnLocation
local areaSize = area.Size * 0.5

local min = area.Position - areaSize
local max = area.Position + areaSize

local PropTable = {}
local PropNum = 0
for i, Prop in game.ReplicatedStorage.Assets.MapProps:GetChildren() do
	PropNum += 1
	table.insert(PropTable, PropNum, Prop)
end
local randomNumForProp = math.random(1, #PropTable)
if randomNumForProp and PropTable[randomNumForProp] then
	local randomProp = PropTable[randomNumForProp]:Clone()
	local x = math.random(min.X, max.X)
	local z = math.random(min.Z, max.Z)
	local y = randomProp.PrimaryPart.Position.Y

	local position = Vector3.new(x, y, z)
	local rotation = CFrame.Angles(0, math.rad(math.random(0, 360)), 0)
	randomProp:SetPrimaryPartCFrame(CFrame.new(position) * rotation)
	
	randomProp.Parent = workspace.Map.Props
	
	local successfullyPositioned = retryPositioning(randomProp, spawnLocation, grass, 0)
end

end

You should use the PivotTo API instead of the deprecated SetPrimaryPartCFrame, like this;

model.Parent = workspace
local pivot = model:GetPivot() * CFrame.Angles(0, math.rad(math.random(0,360)), 0)
model:PivotTo(pivot)

Although for your current question, you can clone
and parent your model to workspace first, then call SetPrimaryPartCFrame,
calling it before parenting won’t apply the CFrame to the model in game, like this;

model.Parent = workspace
model:SetPrimaryPartCFrame(
  CFrame.new(position) * CFrame.Angles(0, math.rad(math.random(0,360)), 0)
)
2 Likes