PivotTo moves model

Issue
When the clickdetector is activated, the position of the Tram model changes as well as the orientation. I wan’t just the orientation to change when I use PivotTo.

Code

local newCF = CFrame.Angles(0, 0, 0) -- Rotate by 180 deg around the Y axis
function Click(Player)
	workspace:FindFirstChild("Tram"..Player.Name):PivotTo(newCF)
	if Player.Character then
		wait(1)
		Player.Character:MoveTo(workspace:FindFirstChild("Tram"..Player.Name).One.VehicleSeat.Position)
	end
end

script.Parent.ClickDetector.MouseClick:Connect(Click)
local newCF = CFrame.Angles(0,math.pi,0) --Rotate 180 degrees relative to the tram, on the Y axis.
function Click(Player)
	local tram = workspace:FindFirstChild(("Tram%s"):format(Player.Name))
	if not tram then return end
	tram:PivotTo(tram:GetPivot()*newCF)
	if Player.Character then
		task.wait(.5)
		Player.Character:MoveTo(tram.One.VehicleSeat.Position)
	end
end)

script.Parent.ClickDetector.MouseClick:Connect(Click)

I cleaned up your code a little bit as well. Try using this script. It will rotate it relative to the tram’s current rotation.

1 Like

It doesn’t move at all now. It just stays still.

try replacing

workspace:FindFirstChild("Tram"..Player.Name):PivotTo(newCF)

with

workspace:FindFirstChild("Tram"..Player.Name):PivotTo(CFrame.new(workspace["Tram"..Player.Name]:GetPivot.Position) * newCF)

Try changing the newCF value, since that will change the orientation.

I want the orientation to change but not the position.

model:PivotTo(CFrame.new(model.CFrame.Position) * rotationCFrame)

What is rotationCFrame??? What is it set as?

ok, lets say you have the vehicle facing the X axis… that would be orientation of (90,0,0)

so in cframe it would be CFrame.Angles(math.rad(90),0,0)

You should check out the different CFrame constructors and functions.

1 Like

But I have not set rotationCFrame as anything so it is incorrect.

The problem has been fixed. Thanks for helping.

You should always mark the post that solved it, as ‘solution’ or at least say how you solved it, so if others have the same or similar issue it can help them out.

10 Likes