Turret keeps breaking my ship

I’m currently working on a roblox naval battle game, but the turrets aren’t going so well. I’ve gotten the rotation working, but right now it breaks the ships, this is a video of what happens:


As you can see, the turret breaks because it’s CFrame is being changed. Is there anyway to prevent it from affecting the rest of the ship?

Scripts:
ServerScript:

(Script removed because this is solved, and i don’t want people to copy it)

LocalScript:

(Script removed because this is solved, and i don’t want people to copy it)

is it welded?

And i don’t think the problem is in the script…

Its

while wait() do

btw

It’s not the script. And yes, it is welded, i tried to use BallSockets but that dosen’t work either, it does what is shown in the video. I also fixed the while wait() do, thanks for telling me about that.

Okay you can try this.

Create a part attach (weld) it to the ship and add a hinge to the top surface
then attach the rotating part to it.

I’ll try that. I’ll tell you if it works or not.

I thought it worked for a second, then it started glitching out again.

Hmm try setting Y to 0???

I’m working on something that may fix it.

No no no wait wait instead of setting its position try putting CFrame

I will make it nocollide, should work.

Edit: It didn’t work. it seems the issue is that the turret keeps lagging behind. I’ll send a video.

Hey you should see this video, and then you will get it what i mean.

He made a turret in this vid.

Also as i said, its because of your Y axis

like if you turn your mouse down or up it will start glitching.

I’m not trying to make raycasting turrets, his turret is anchored, mine can’t as it’s a mobile ship. You can see the issue below:


The turret is lagging behind the hinge point, all i want is for it to work. Then i can make it better by making it not fall over like it is in the video.

try doing this

turret.TurretBase.Position = Vector3.new(turret.TurretBase.Position.X,0,turret.TurretBase.Position.Z)

Oh, that part. I’ll try doing that, i made it do that when it had collisions on to prevent it from clipping into the ship.

Still doesn’t work.

Wait let me explain.

When you are turning your mouse left and right its working
but when you turning it up / down ( y axis ) it will start glitching.

Well, i’ll do a bit of research quickly.

image
Nope. It’s lagging behind, like i said.

Not actual lag, but just broken physics. Is there a way to fix this?

Okay wait. Let me try it myself.

Maybe try setting both model’s Network Owner to the player?

I don’t exactly know how to do that, but it’s not going to do anything. This is setting the CFrame to point at the mouse, and setting the network owner to the player won’t help with stopping it from lagging behind.