Rotating mechanic

I’ve tried a bunch of methods for a rotating mechanic for my building game, and most of them failed. What would be a good way of rotating the part i’m placing? I think this is a good way of rotating the part but idk how to make it work:

If anybody has any tips or methods to code this mechanic i would really appreciate that. I know i can’t ask for people to make entire scripts for me on this forum but i’m not asking for scripts i just want to know how you would go about this? Thanks!

If I understood you correctly, you want an object to rotate around some position.
You can look at a code I’ve written for a door that rotates around a hinge and get a clue on how you can implement such a mechanic:

-->> Services
local runService = game:GetService("RunService");

-->> References
local door = script.Parent;
local hinge = door.Parent;

-->> Functions & Events
local angle = 0;
local cycleTime = 3
function Heartbeat(dt)
	angle += dt*(2*math.pi/cycleTime)
	local x = math.cos(angle)*(door.Size.Z + hinge.Size.Z)
	local z = math.sin(angle)*(door.Size.Z + hinge.Size.Z)
    door.Rotation = Vector3.new(0, 90 - angle*180/math.pi, 0)
	door.Position = hinge.Position + Vector3.new(x/2, 0, z/2)
end;

runService.Heartbeat:Connect(Heartbeat)
1 Like