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