Turret Rotate Problem

Hello. I was working on a turret(for the first time) then I wrote a simple script that would rotate the turret

Here is my script :

while true do

wait(0)

script.Parent.CFrame = CFrame.new(script.Parent.Position, game.Workspace["F-16C Fighting Falcon"].Position)

wait(0)

end

This is how it looks like in the game

As you can see my turret is broken How do I prevent that from happening(also I don’t know what is that broken part of the turret is called and sorry for bad grammar)

Assuming there are no errors, try making the waits longer. Also, is Workspace["F-16C Fighting Falcon"] a model? If it is, try retrieving the position value of one of it’s parts.

Its a mesh that i found the part of turret is not correct and i dont know what to do

why dont you use rotation instead of position

Yeah I had the same problems as well, if the part not orientated (0,0,0) then the CFrame constructor will treat the way the turret should face up wrong like what has happened.

To fix this you can add a offset rotation CFrame in order to correct it out like so:

while true do

wait(0)

script.Parent.CFrame = CFrame.new(script.Parent.Position, game.Workspace["F-16C Fighting Falcon"].Position)

script.Parent.CFrame *= CFrame.fromOrientation(a,b,c)
wait(0)

end

You will have to find the correct a,b,c values to orientated it correctly which you can do by using an Attachment CFrame. An example is in my resource which I made for these types of situations:

I tried to set the turret orientation to jet but it only rotates and became more worse

Thanks! But how do I check if turret is rotating so i can play rotate sound

And how do i check if its currently facing the target

Thanks! But how do I check if turret is rotating so i can play rotate sound

And how do i check if its currently facing the target