Part wont CFrame correctly

So, I want this gun to stick to the players body and be rotated with the mouse.
I do this by getting the mouse position and sending it to the server with a remote event every frame with renderstepped.
For some reason this happends:


There are no errors or anyting, but I’ve figured out that every variable is what it should be.

Here’s the server side code:

And here’s the client side:

Any help would be appreciated!

Do the guns rotate around the body or are they to be fixed to a spot on the body?
If they are to be fixed to the body make them massless and weld them there.
Is this the only gun set up.. if so; You could even make them there all the time that way, then use transparency for showing or not.

Going to have a hard time updating that as is.

I have part called “Root” in every gun that’s in the middle of the gun, the Root is welded to the rest of the parts in the gun so when you rotate the root, everything else in the gun also rotates. The roots postion should be the same as the humanoidrootpart’s.

Instead of changing the CFrame the the gun, you should weld it to the character (this does make it harder to set the CFrame, as you’ll have to work with relative CFrames, but Weld.C0 = HumanoidRootPart.CFrame:ToObjectSpace(CFrame.lookAt(HumanoidRootPart.Position, MousePos.Position)) should work I think (Weld.Part0 being the HumanoidRootPart, and Weld.Part1, being the gun. I think, might need to be the opposite)

This would be with Weld objects, not WeldConstraint (as those don’t have the C0 and C1 properties)

Currently, the gun looks like it is falling, because well it is. Your gun is unanchored, and updated on the server. Replication from the server to the client (and vice versa), is not consistent, it can take more or less time depending on the network, so you cannot rely on sending data every frame, for the server to apply that data every frame as well (the client’s fps might also be higher, or lower)… The server might also replicate the gun’s information every other frame to reduce network usage

By welding the gun to the character, you avoid these issues. It also becomes possible to send the mousePos data less often (reducing network usage), and perform interpolation to keep things smooth (idealy on every client, otherwise, the network would make the interpolation from the server jittery)

2 Likes

Please do NOT send a signal to the server every frame under any circumstances. It is completely unnecessary and slows the game down greatly, and also produces input delay. Better way to do this is to set the network owner of the gun to the player when you are instancing it, and setting its rotation on the client instead. Doing this will replicate to other clients and the server, and remove input delay.

Now that we got that out of the way, the reason why it keeps falling, is because it is not welded to the character. All you need to do is add a WeldConstraint, and weld it to the HumanoidRootPart preferably.

1 Like

You should anchor your model I actually wouldn’t weld in this case because what if your want to do something cooler like lerp the model?
Just anchor the model so gravity doesn’t affect it.
I would also use quenty spring module to make it look more physical.

1 Like

I didn’t even see this, but don’t set the position on the server, give the client network ownership of your gun model thing and set if from the client

Thank you very much for your solutions, this will help me very much. Sadly i can’t set them all to solutions.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.