Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to switch animation back to normal?

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

✓ Accepted answer

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.

1 comment

0

Thank You!

This discussion is preserved as it was. New answers, comments, and votes are closed.