I’m making a TPS projectile gun and here’s what it looks like in the explorer:
Now here’s the issue.
I’m positioning my gun with an animation and for some reason it doesn’t replicate to the server? When my projectile shoots it shoots from somewhere near the origin to my mouse position. How can I make the position of my gun where it actually is on my screen?
If the animation is a descendant of a Humanoid or AnimationController in a player’s character then animations started on that player’s client will be replicated to the server and other clients.
If the animation is not a descendant of a player’s character, its animations must be loaded and started on the server to replicate.
@EndzyDaBoi I have an animation inside a replicatedstorage that is played with a local script inside a tool which has a animation loaded into the humanoid. The animation should still replicate to the server as per usual unless you’re doing something different.
Just to clarify how animations replicate… the animations will replicate from the server to client and vice versa whether you load it and play it from the client or server. That actual replication is from the Animator object which is created server side when the game loads your character. If this Animator object is created on the client side then the animations will not replicate, if it created on the server side they will replicate. If your humanoid / animationcontroller does not have a pre-existing Animator object, a new one will be created when you use LoadAnimation. If this load animation is done from the client side the Animator object will be client sided and not replicate to the server, if the load animation is server sided the Animator object will be server sided and it will replicate.
What actually would be the use case in creating an animation on the client/server, loading it into the humanoid, then playing it? Can’t the same thing be done while replicating as per usual by just creating the animation beforehand plus it’ll allow you to have other scripts to easily preload it just in case?
I just find it odd that some people still create animations on the scripts rather then actually just having it on hold.
You aren’t per say loading the actual animation object, you are creating the AnimationTrack object (which cannot be created before hand). The LoadAnimation function is the only way to create this object which is the thing that allows you to play the animation on the humanoid/controller. If you look at the API for LoadAnimation it takes in the Animation object which is what you’re likely referring to and creates the AnimationTrack out of it.
Yes actually I have the “Animation” object in a folder inside the tool.
Should I be creating it on a server script inside the tool and then playing it on the client with a localscript (still inside the tool)?
Either way is fine it just depends on if you need to access the actual object from the server or not. If you create it on the client only the client can access it, but the actual animation movement will still replicate to the server. You can actually just pre-create these objects in studio so you don’t need to create them via a script which it looks like you did. But like I said above, if your animation is not replicating it’s likely due to an issue with the Animator object.
Going back to your original question though, you should post your script so that we can see what you’re doing. If you’re doing any sort of manual movements or welds in your LocalScript, that is likely why your gun appears somewhere else on the server compared to the client.
Yea it looks like your issue is your Grip motor6d, you’re creating that on the client and not the server so the server doesn’t see the gun as welded. I believe the Tool object will make a weld for you given the right conditions. I am assuming your gun model is welded, so try simply dragging the handle part (must be named Handle I think) and put it directly under the tool object in the explorer. This should make the tool create a weld for you. If you would rather not do this, then another solution is to simply create and weld the gun to a motor6d on the server side.