Do animations not auto replicate?

Hi

I’m making a TPS projectile gun and here’s what it looks like in the explorer:
image

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?


1 is where my gun is on my screen.
2 seems to be where my gun actually is??

Very confused, any help is appreciated.
Thanks for reading.

If you would like animations to replicate, consider using an AnimationController or, loading the animation via a server script.

When I’ve made a sword slash script, I fired a RemoteEvent on Tool.Activated and then ran animations with the server.

3 Likes

So wait they don’t replicate to the server on being played?
Why does everyone say they do then…

How do I use the AnimationController correctly to replicate it to the server?

Also: When animating a model, once the animation is playing the model position DOES change to where it is in the animation correct?

You’d need to use Motor3 for the model position to move.

I’ve attached an hyperlink to my previous comment, read about AnimationController.

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.

7 Likes

It’s a tool in starterpack so technically that means it should be played on the client right?

@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.

9 Likes

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.

1 Like

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.

1 Like

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)?

1 Like

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.

1 Like

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.

Client:

local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService") 
local RunService = game:GetService("RunService")
local Shot = ReplicatedStorage:WaitForChild("EndzyTPS_REMOTES"):WaitForChild("Shot")
local Gun = script.Parent.Gun
local AK_47 = script.Parent

local Animations = Gun.EndzyTPS.Animations
local Configs = Gun.EndzyTPS.Configs
local Mouse = LocalPlayer:GetMouse()

local Grip
local IdleAnim
local AimAnim
local IsAiming = false
local TrackMouse

local UI = LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("GunUI")

local Shoot
local Tracker

-- // Initialize

AK_47.Equipped:Connect(function()
	Grip = Instance.new("Motor6D")
	Grip.Parent = Character:WaitForChild("Torso")
	Grip.Name = "GunAttach"
	Grip.Part0 = Character:WaitForChild("Right Arm")
	Grip.Part1 = Gun.RArm
	IdleAnim = Character:WaitForChild("Humanoid"):LoadAnimation(Animations.Idle)
	IdleAnim:Play()
	print("playing")
	UI.Frame:TweenPosition(UDim2.new(0.676, 0,0.762,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)
	
	Mouse.Icon = "None" -- rbxassetid://2819637893
	
	Tracker = LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("MouseOverlay") -- local 
	Tracker.Enabled = true
	
	TrackMouse = RunService.RenderStepped:Connect(function()
		Tracker.Cursor.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
	end)
	
	
	
	
	Shoot = UserInputService.InputBegan:Connect(function(input, gpe)
		if gpe then return end
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			print("clicked")
			AimAnim = Character:WaitForChild("Humanoid"):LoadAnimation(Animations.Aim)
			AimAnim:Play()
			IsAiming = true
			---------------------------------- SHOOTING :D
			wait(0.01)
			Shot:FireServer(Mouse.Hit.Position, Mouse.Target, Configs.Ammo.Value, Gun.BulletPoint.CFrame.Position)
			
		end
	end)
	
end)

AK_47.Unequipped:Connect(function()
	Grip:Destroy()
	IdleAnim:Stop()
	UI.Frame:TweenPosition(UDim2.new(1.1,0,0.762,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)
	Shoot:Disconnect()
	Mouse.Icon = ""
	Tracker.Enabled = false
	TrackMouse:Disconnect()
	
	
	if IsAiming then 
		AimAnim:Stop() 
		IsAiming = false
	end
end)

Still a work in progress so some stuff might look half-baked because it’s not finished.

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.

Wait im confused.

The gun itself is in a MODEL which it doesnt really need to be I guess since everything is welded together with default ManualWelds.

Do I just need to move the handle under the object itself and it’ll remain the way I’ve done my animation and everything?