Spawned model is rotated relevant to the camera

I’m making an ability where you press E to create a box at the mouse cursor. It spawns in the right position, but it’s always rotated in a weird manner and the camera angle seems to be affecting that.
image
I’ve tried PivotTo: and SetPrimaryPartCFrame: but the rotation is still there. How can I make it so that it spawns with the original rotation of the model instead of being weirdly rotated?

local rs = game:GetService("ReplicatedStorage")

script.Parent.TrapPlaceEvent.OnServerEvent:Connect(function(player,mouse,mousecframe,mousepos)
	local trap = rs.illuminatrap:Clone()
	trap.Parent = workspace
	trap:SetPrimaryPartCFrame(mousepos)
	trap:WaitForChild("primary"):Destroy()
	local children = trap:GetChildren()
	for i = 1, #children do
		wait(0.025)
		children[i].Transparency = 0.9
		wait(0.025)
		children[i].Transparency = 0.8
		wait(0.025)
		children[i].Transparency = 0.7
		wait(0.025)
		children[i].Transparency = 0.6
		wait(0.025)
		children[i].Transparency = 0.5
		wait(0.025)
		children[i].Transparency = 0.4
		wait(0.025)
		children[i].Transparency = 0.3
		wait(0.025)
		children[i].Transparency = 0.2
		wait(0.025)
		children[i].Transparency = 0.1
		wait(0.025)
		children[i].Transparency = 0
	end
end)

Just set the position not the cframe, cframe affects both position and rotation,

--trap:SetPrimaryPartCFrame(mousepos)
trap.Position = Vector3.new(mousepos)

Since you can’t set the position of a model you should combine the pre existing rotation from your pivot & merge it with your goal position.

what is the client script?

script.Parent.TrapPlaceEvent:FireServer(mouse, mouse.Hit, Vector2.newmouse.X, mouse.Y) 
-- The first argument does not work

also you should use TweenService because my skin itches when I see this

change it to

children[i].Transparency = 1
game:GetService("TweenService"):Create(children[i],TweenInfo.new(0.25), {Transparency = 0)
1 Like

I figured it out. It had to do with :GetPivot()