Need help with Cylinder rotation

Hello! I need help with my cylinder rotation script, what I want to achieve is that the cylinder moves 360 degrees depending on where the other part is, the problem is that the cylinder does not move as it should.

This is an example of how it should move:

The cylinder should see the other part, but it is not exactly what happens, sometimes if the part is a little upwards the cylinder moves looking up but that should not happen, the only thing I want is for the cylinder to be move 360 degrees sideways depending on where the part is.

Here is my scipt:

while true do
	local ts = game:GetService("TweenService")
	local tinfo = TweenInfo.new(3)
	
	local part = script.Parent
	local Part2 = script.Parent.Parent.Part2
	local properties = {CFrame = CFrame.new(part.CFrame.Position, Part2.CFrame.Position) * CFrame.Angles(0, 0, math.pi/2)}
	
	
	local tween = ts:Create(part,tinfo,properties)
	tween:Play()
	tween.Completed:Wait()
end

Any help is appreciated :slight_smile:

try this :

script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(the goal part) * CFrame.new(0, 0, 0)
 wait(0.001)

put this into

this

it should work

the other parts goal you want rotate

local rot = workspace:WaitForChild("Rot") -- My rotate part
local target = workspace:WaitForChild("Target") -- Part to look at

game:GetService("RunService").RenderStepped:Connect(function()
	rot.CFrame = CFrame.new(rot.Position, Vector3.new(target.Position.X, (rot.Size.X/2), target.Position.Z)) * CFrame.Angles(0, 0, math.pi/2)
end)

With that I got this result:
https://gyazo.com/7e54ec5839bc2f2135389658da2dac00

2 Likes