Animation can't replicate to server

The title said it all, animation can’t replicate to server. Recently, i tried to simulate the FPS equipped pose using animation instead of fake arms like many people. I was stuck in this problem that seems not to have an answer yet. I tried everything from loading animation on client to using an animator, it seems that if i load the animation on the server, it still gonna work but there is a problem, i can’t loop the poseanimation in server because runservice seems not to work in server-side and using while loop will cause lag because if you imagine 15-20 players running while loop simultaneously, the server might crash

. The reason i did this is because i can’t pause the animation at a certain position for some reason so another guy in the forum suggested another way, create another animation that loops the last frame of the original animation.

This works but it doesn’t replicate, any suggestion, i would be really appreciate.
Here is the code:
localscript:

repeat
	wait()
until game:IsLoaded()
local player = game.Players.LocalPlayer
repeat
	wait()
until player.Character.Humanoid.Animator
local animator = player.Character.Humanoid:WaitForChild("Animator")
local contextactionservice = game:GetService("ContextActionService")
local tool 
local runservice = game:GetService("RunService")
local function binding(name,inputstate,inputobject)
	if name =="pose" and inputstate == Enum.UserInputState.Begin then
		local FPS = animator:LoadAnimation(script.Animation)
		FPS:Play()
		FPS.Stopped:Wait()
		tool = runservice.RenderStepped:Connect(function(dt)
			local poseanimation = animator:LoadAnimation(script.poseanim)
			poseanimation:Play()
		end)
	elseif name == "reverse"and inputstate == Enum.UserInputState.Begin then
		tool:Disconnect()
	end	
end
contextactionservice:BindAction("pose",binding,true,Enum.KeyCode.E)
contextactionservice:BindAction("reverse",binding,true,Enum.KeyCode.R)

serverscript:

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character 
	if char then
		local animator = Instance.new("Animator")
		animator.Parent = char.Humanoid
	end
end)

Note: i used animator because it is not safe to use humanoid:LoadAnimation due to the documents in devhub said that it was deprecated.

Make a new animation with just the final equip pose and set it to loop in the animator
Play it once on the client after the weapon equip animation ends(subscribe an event to its finish and play the hold animation). And stop it when unequiping/other animations. This is how I do it, however, I use the fake arm viewmodel method so it might be different.

Sorry if I misunderstood the quesition.

Don’t you see i used RenderStepped? that is for looping the final animation

you do not need to do that. The roblox animation editor has a built in loop option for animations. Using this instead of playing the animation should alleviate some of the lag.

Ok that is new, where is it? Those animations make me so frustrated these days

On the top bar of the animation editor with the play button, there is a play button with a circle going around it. That is the loop button.
image
It is circled in green in this image.

so you are saying that pressing this button will make the animation loop?

Yes, and then just set the animation to play once instead of playing it over and over again in a loop. Put the holding weapon animation pose in the first frame and loop it. When played it will play this stagnant animation over and over until stopped.

1 Like

thank you so much, it works but the reverse couldn’t work

never mind, it works again. Thanks a lot for your help