Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to switch animation back to normal?

Asked by 5 years ago

Inside of a sword I have a local script inside called Animation. Everything works perfect, it plays the animations at the right time.

My issue is that when you unequip the tool, it still keeps the animations the same even after re-enabling the original Animate script.

local idle = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.idle)
local jump = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.jump)
local run = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.run)
local attack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.attack)
script.Parent.Equipped:Connect(function()
    idle:Play()
    script.Parent.Parent.Animate.Disabled = true
    game.Players.LocalPlayer.Character.Humanoid.Jumping:connect(function()
        jump:Play()
        game.Players.LocalPlayer.Character.Humanoid.StateChanged:connect(function()
            local state = game.Players.LocalPlayer.Character.Humanoid:GetState()
            if state == Enum.HumanoidStateType.Landed then
                jump:Stop()
                idle:Play()
            end
        end)
    end)
    game.Players.LocalPlayer.Character.Humanoid.Running:connect(function(speed)
        if speed > 0 then
            run:Play()
            idle:Stop()
        elseif speed == 0 then
            run:Stop()
            idle:Play()
        end
    end)
    script.Parent.Unequipped:connect(function()
        game.Players.LocalPlayer.Character.Animate.Disabled = false
    end)
end)

Whether the Unequipped function is inside or outside of the Equipped function, it's the same results.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I'm assuming the script you posted in the Animation script relative to the Sword?

When you first load the character into the game, ROBLOX will pre-define the animations for you.

However, since this script loads new animations to replace those that were defaulted at the beginning of the game, I suggest you add a clause to the Tool.Unequipped function so that you reload the old animations (possibly copy the player's animation ids when they join?, since players may be using animation bundles) and reinsert the ids of the following animations

local idle = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.idle)
local jump = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.jump)
local run = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.run)

With their original values

local oldidle = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(IdleAnim)
local oldjump = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(JumpAnim)
local oldrun = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(RunAnim)

You can copy these IDs from the Animation Script that appears when you test the server.

0
Thank You! IScriptThat 5 — 5y
Ad

Answer this question