Merging 2 CFrames into 1 part/model?

Hello everyone! So i am making a mini gun turret for my new game that aims/looks at the player’s mouse and I’ve decided to have the barrel spinning (Barrel will spin when you shoot with the turret) done on the client instead of the server to reduce some lag. And i have run into a snag…
So since I am doing the spinning on the client, i have to hide the barrel on the server side (Hiding it for the client using the turret so there aren’t 2 barrels inside each other) and clone the barrel on the client side to be able to actually spin it. Because of this, i have to set the position and angle of the barrel to match the server sided one, and be able to spin at the same time, which turns out to be quite a painstaking task to do/figure out. Here is what i have tried to do already:

spinner:SetPrimaryPartCFrame(prevgun.GunHori.GunVert.Spin:GetPrimaryPartCFrame())
		spinner:SetPrimaryPartCFrame(spinner:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(rot), 0, 0))

prevgun = the barrel on the server side
spinner = the barrel on the client side

So on the first line, I set the barrel on the client side to match the barrel on the server side. On the second, It would theoretically actually do the spinning. But what ends up happening is the client sided barrel matches with the server sided barrel, but does not spin. So my issue/question is, how would i be able to keep the position and the angle of the server sided barrel, but also be able to continually rotate and spin it? I should also note i have never done succeeded from doing something this advanced with the CFrames. Any help will be greatly appriciated! :smiley:

Edit: Let me know if you need more details, I’ve tried to include as much detail as i could.

I’m not very clear on how you’re setting up the networking for this, but as far as spinning something goes, you would use the Z axis

--roll a part 90 degrees:
part.CFrame = part.CFrame * CFrame.angles(0, 0, math.rad(90)) --math.pi/2

Also, something very important for you to change is to stop using SetPrimaryPartCFrame, as it will create imperfections in your model if you use it too many times. I made a module that will let you change the cframe of a model continuously without this problem.

I would do all of this by animating the turret on the client and sending the position (target) to the server. The server would then tell every other client where the turret is aiming, and each would animate the turret independently.
The server would operate an invisible version of the turret that shoots invisible bullets, and these bullets are what would be used for hit/damage detection

1 Like

Thank you! I never knew that SetPrimaryPartCFrame did that… I did notice that one of the parts in barrel of the turret was getting offset a tiny bit and i had no idea that it was SetPrimaryPartCFrame the entire time. I’ll give your module a try, and do the aiming on the client side. Thanks again!

Edit: Also, I’ve been rotating the barrel on the X axis because I originally built the model facing the negative X axis… Something i almost always forget to do is to build something facing negative Z…