Animate Script Changing Mid-Game

I am trying to complete an Idle animation switch mid-game during a stand summon. My game is a stand game, and it requires different stands to have a different idle for the host.

Every time I load a new idle animation, when the ID is changed, it plays for only the client, and overlaps for the server. For other players, the animation does not play fully. Then when the animation is stopped, it doesn’t return to the original animation.

I have tried playing the animate script on the server, which was very delayed and did not work. Either way I try to fix it, I can not find a solution on the Dev Forum. I must gain explanation.

Pre-Animate ID Change
image_2025-02-08_201217536

Post-Animate ID Change
image_2025-02-08_201055559
Screenshot 2025-02-08 201045

Check if animations are synchronized across all clients and the server by using remote events to communicate animation changes from the server to all clients. You also need to implement a system where the server handles the logic for changing animations, and clients replicate the server’s instructions. And use animation tracks to manage animations, making proper transitions by stopping the previous animation before playing the new one.

I have created a remote event to a server script, and the server script fires the event to the client. It works, though when it does the function, stopAllAnimations() (Animate script) it does it for all clients. This causes all animations to be stopped in all players.

Then you need to implement a player-specific animation control system that ensures each client only manages its own animations.

Server-side script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local remoteEvent = ReplicatedStorage:WaitForChild("AnimationEvent")

-- Function to handle animation changes for a specific player
local function changePlayerAnimation(player, animationId)
    -- Validate the player and animationId
    if not player or not animationId then
        warn("Invalid player or animationId")
        return
    end

    -- Fire the RemoteEvent to the specific player
    remoteEvent:FireClient(player, animationId)
end

-- Example usage: Change animation for a specific player
Players.PlayerAdded:Connect(function(player)
    -- Listen for a trigger to change the animation (e.g., a button click or stand summon)
    player.CharacterAdded:Connect(function(character)
        -- Replace "StandSummonTrigger" with your actual trigger mechanism
        local trigger = character:WaitForChild("StandSummonTrigger", 10)
        if trigger then
            trigger.Activated:Connect(function()
                changePlayerAnimation(player, "ANIMATION_ID")
            end)
        end
    end)
end)

Client-side script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

local remoteEvent = ReplicatedStorage:WaitForChild("AnimationEvent")

-- Track active animations
local activeAnimationTrack = nil

-- Function to stop the current animation
local function stopCurrentAnimation()
    if activeAnimationTrack then
        activeAnimationTrack:Stop()
        activeAnimationTrack = nil
    end
end

-- Function to play a new animation
local function playAnimation(animationId)
    -- Stop the current animation
    stopCurrentAnimation()

    -- Load and play the new animation
    local animation = Instance.new("Animation")
    animation.AnimationId = "rbxassetid://" .. animationId
    activeAnimationTrack = animator:LoadAnimation(animation)
    activeAnimationTrack:Play()
end

-- Listen for the RemoteEvent to change animations
remoteEvent.OnClientEvent:Connect(function(animationId)
    playAnimation(animationId)
end)

I am not sure I have done it right because it is no different. Here is my code. Can you point out an error for me?

Animate Script: (This is the part where the idle animation quickly updates)

Server Script:

Client Script:

Now that i checked again, in the code i wrote the server incorrectly fires FireAllClients() . And the client script fails to properly reference animations.

Server-side script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage.Events:WaitForChild("CharIdle")

local function changePlayerAnimation(player, animationId)
    if not player or not animationId then return end
    remoteEvent:FireClient(player, animationId) -- Target specific player
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        
        ReplicatedStorage.Events.Summon.OnServerEvent:Connect(function()
            changePlayerAnimation(player, "YOUR_ANIMATION_ID")
        end)
    end)
end)

Client-side script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local remoteEvent = ReplicatedStorage.Events:WaitForChild("CharIdle")

local originalIdleTrack = animator:LoadAnimation(script.Parent.idle.Animation1)
local activeTrack

remoteEvent.OnClientEvent:Connect(function(animationId)
    if activeTrack then activeTrack:Stop() end
    
    -- Override default Animate script behavior
    originalIdleTrack:Stop()
    
    local newAnimation = Instance.new("Animation")
    newAnimation.AnimationId = "rbxassetid://"..animationId
    activeTrack = animator:LoadAnimation(newAnimation)
    activeTrack.Priority = Enum.AnimationPriority.Idle
    activeTrack:Play()
end)

It works, though when the character moves it is stuck on the idle animation. Also, how would I be able to make it return to its original idle when the stand is returned back to the host? I tried debounces, though it stuck on the original idle instead. I believe it would be because the animate script is playing the movement animations as core? How would I change that?