Need Help with Overwriting Animations while Equipping/Unequipping Weapon

Hello, I’ve made this script to replace the animation IDs for when this sword is equipped and when it is unequipped (and it works fine). However, whenever the sword is equipped/unequipped, as seen in the video I linked, the previous animation is still played until I completely stop moving, which then the proper animation plays.

How can I make the animations fluidly transition/overwrite each other and stop the problem? Here is my full script:

--Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local StarterPack = game:GetService("StarterPack")

--Variables
local Tool = script.Parent
local ToolStats = require(ReplicatedStorage.ItemData:FindFirstChild(Tool.Name, true))
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local EquippedItem = ReplicatedStorage.Events.Equipped
local UnequippedItem = ReplicatedStorage.Events.Unequipped

local Attack = Tool:WaitForChild("Attack")
local Block = Tool:WaitForChild("Block")

local AnimateScript = Character:WaitForChild("Animate")
local Animator = Humanoid:WaitForChild("Animator")
local DefaultIdle = "rbxassetid://129666379856115"
local DefaultWalk = "rbxassetid://117691645809776"
local SwordWalk = "rbxassetid://75651293536523"

--Functions
local function UpdateAnimations(toolName)
	if toolName == "Starter Sword" then
		print("Updating animations to Sword animations")
		AnimateScript.walk.WalkAnim.AnimationId = SwordWalk
		AnimateScript.run.RunAnim.AnimationId = SwordWalk
	else
		print("Resetting to normal animations")
		AnimateScript.walk.WalkAnim.AnimationId = DefaultWalk
		AnimateScript.run.RunAnim.AnimationId = DefaultWalk
	end
end

local function ToolEquipped(tool)
	if tool:IsA("Tool") then
		print("Tool equipped: " .. tool.Name)
		UpdateAnimations(tool.Name)
	end
end

local function ToolUnequipped()
	print("Tool unequipped.")
	UpdateAnimations(nil)
end
--Events
Tool.Equipped:Connect(function() 
	ToolEquipped(Tool) 
end)

Tool.Unequipped:Connect(function()
	ToolUnequipped(Tool)
end)

UserInputService.InputBegan:Connect(function(input) -- Attacking
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("Left mouse was clicked only.")
		Attack:FireServer()
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		print("Right mouse was clicked.")
		Block:FireServer()
	end
end)

Video link of issue:

I believe you would have to turn of animation loop in the animation editor

Nope, it doesn’t work, it just makes you pretty much A-Pose after the animation is done.

1 Like

Alright then well I would try messing around with animation priority Try to make your walking animation have more priority than the sword if that doesn’t work then I’m not sure

1 Like

Unfortunately, that didn’t work either; I’m not really sure why anything I try doesn’t exactly work, and now whenever the character is reset the animation script doesn’t even work anymore. Oh well, I appreciate the help regardless!

1 Like