Animation only playing on server side

Hi i have this tool which when equipped plays an animation on a character
and then when it is unequipped, it plays another animation(most specificly the animation it had before the tool was equipped)
the problem is, the animation playing when unequipped doesnt play. It only plays on the server and not the client somehow.

I wanted the animation to be seen by other players and not locally

here’s the script:

local tool = script.Parent.Parent

tool.Equipped:Connect(function()
    local player = tool.Parent
    local kbot = workspace:WaitForChild(player.Name.."'s K-BOT")

    local animator = kbot:WaitForChild("Humanoid").Animator
    local animations = {
        ['Power'] = {
            ['animation'] = animator:LoadAnimation(kbot.animations.Power), 
            ['face'] = function()
                kbot.face.BrickColor = BrickColor.new('Really red')
            end}
    }

    local loadAnimation = animations['Power']['animation']
    loadAnimation.Priority = Enum.AnimationPriority.Action
    loadAnimation.Looped = true
    loadAnimation:Play()
    animations['Power']['face']()
end)

tool.Unequipped:Connect(function()
    local player = tool.Parent.Parent
    local kbot = workspace:WaitForChild(player.Name.."'s K-BOT")

    local animator = kbot:WaitForChild("Humanoid").Animator
    local animations = {
        ['Idle'] = {
            ['animation'] = animator:LoadAnimation(kbot.animations.Idle), 
            ['face'] = function()
                kbot.face.BrickColor = BrickColor.new('Electric blue')
            end}
    }

    local loadAnimation = animations['Idle']['animation']
    loadAnimation.Priority = Enum.AnimationPriority.Action
    loadAnimation.Looped = true
    loadAnimation:Play()
    animations['Idle']['face']()
end)

video:

1 Like

did you stop the other equipped animation after playing the unequipped one?

1 Like

Your script is server-sided, simply make your script a local script!

will the animation replicate to the server tho?

You could fire a remote event to the server to execute the Animation, that way as of my knowledge It will replicate.

if you’re animating the bot owned by the server, then you play it inside a server script with an animationcontroller for it to replicate.

If I’m correct, animations played on local will always play on server as well. My proof is that the entire Animate script is a local script, yet animations play on the server as well. In your case, use remote events to change anything like the head color on the server, then play the animation the client?

are you aware that you never stop the equipped animation in that script?

yeah, i just dont really know how to stop it since the loadanimation variable is in a different function

load the animation outside of both the functions, just play the animation inside each of them. Also is the robot a descendant of the character or workspace?

1 Like