Firing animation change to everyone

I have a local script that handles animation change.

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

-- Remember to select the animation objects and set the ids to your own!
local walkAnim = script:WaitForChild("Walk")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)

local idleAnim = script:WaitForChild("Idle")
local idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)

local function playWalkAnimation()
	if not walkAnimTrack.IsPlaying then
		walkAnimTrack:Play()
	end
end

local function playIdleAnimation()
	if not idleAnimTrack.IsPlaying then
		idleAnimTrack:Play()
	end
end

local function stopWalkAnimation()
	if walkAnimTrack.IsPlaying then
		walkAnimTrack:Stop()
	end
end

local function stopIdleAnimation()
	if idleAnimTrack.IsPlaying then
		idleAnimTrack:Stop()
	end
end

local function isMoving(humanoid)
	return humanoid.MoveDirection.Magnitude > 0 and humanoid.WalkSpeed <= 19
end

humanoid.Running:Connect(function(speed)
	local currentState = humanoid:GetState()
	if isMoving(humanoid) and currentState ~= Enum.HumanoidStateType.Jumping and currentState ~= Enum.HumanoidStateType.Freefall and humanoid.FloorMaterial ~= Enum.Material.Air then
		playWalkAnimation()
		stopIdleAnimation()  -- Stop idle animation if playing
	else
		stopWalkAnimation()
		if humanoid.MoveDirection.Magnitude == 0 then
			playIdleAnimation() -- Play idle animation when not moving
		else
			stopIdleAnimation() -- Stop idle animation when moving
		end
	end
end)

local function reloadIdleAnimation()
	idleAnimTrack:Stop()
	idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)
	idleAnimTrack:Play()
end

-- Stop the animation when the player lands after jumping
humanoid.StateChanged:Connect(function(oldState, newState)
	if oldState == Enum.HumanoidStateType.Freefall and newState == Enum.HumanoidStateType.Physics then
		if not isMoving(humanoid) then
			stopWalkAnimation()
			playIdleAnimation() -- Play idle animation when landing after jumping
		end
	end
end)

idleAnim.Changed:Connect(reloadIdleAnimation)

image

It works client side, the user sees the animation.

Anim changer local script

local idleAnimAsset = script.Parent
local rs = game:GetService("ReplicatedStorage")
local animChangerRemote = rs:WaitForChild("AnimChangerRemote")

animChangerRemote.OnClientEvent:Connect(function(animId)
	idleAnimAsset.AnimationId = animId
end)

The example server script where im firing

local animChangerRemote = replicatedStorage:WaitForChild("AnimChangerRemote")

local Aura_animId = "rbxassetid://16682286652"
local Default_animId = "rbxassetid://16656769930"
local animId

local function Changeanim(player)
  animChangerRemote:FireClient(player, animId)
end

When the animation changes for me, the other users see both animations kinda mixed up in one, and when i remove the animation, other players still see it mixed so im trying to figure a way how to make it synced

1 Like

Maybe stop all of the currently playing animations, which you can get them by using Animator:GetPlayingAnimationTracks() before loading the new idle animation

it did not work…

local function reloadIdleAnimation()
	Animator:GetPlayingAnimationTracks()
--stopped them here but forgot the code for it
	idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)
	idleAnimTrack:Play()
end

basically ive stopped all anims and played it, but the two animations are still kinda playing at the same time or something

if it did not work initially by disabling the idle then playing another one then this shouldnt work either

Are the two animations the idle and walk?

no, the two colliding animations are the default idle and the new idle, but on my screen its fine, it’s jus a problem on other’s screen

Maybe you can try increasing your animation priority and then publishing it again with the new priority?

If you want to disable the default animate script, you can also put an empty local script named “Animate” inside the StarterCharacterScripts

I don’t use the Animate for animations, I use two local custom scripts, the problem is

There’s a default animation loaded which is MY custom default idle

Then, I fire the server replacing that animation in the local script

On my screen its fine,

On the server when somebody looks at me, these two collide and when i fire the server again to remove the new idle and go back to default, they still collide until i reset

try destroying the old idle animation track

That might actually work imma try later