Animations not changing when id is changed

So the title says it all

local ToolSystem = function(Player)
	if Player then
		--Player
		local Character = Player.Character or Player.CharacterAdded:Wait()
		local Humanoid = Character:WaitForChild("Humanoid")
		--Variables
		local AnimationModule = require(script.AnimationsModule)
		local ContentProvider = game:GetService("ContentProvider")
		--Animations
		local Animation = script:WaitForChild("Animation")
		local IdleAnimation = Animation:WaitForChild("IdleAnimation")
		local GetCharacterTool = function()
			for i, v in pairs(Character:GetChildren()) do
				if v:IsA("Tool") then
					return v
				end
			end
		end
		
		local ToolHandler = function()
			local Tool = GetCharacterTool()
			local LoadIdleAnimation = Humanoid.Animator:LoadAnimation(IdleAnimation)
			
			if Tool then
				Tool.Equipped:Connect(function()
					for i, Tables in pairs(AnimationModule) do
						if Tables.Name:match(Tool.Name) then
							LoadIdleAnimation:Play()
							IdleAnimation.AnimationId = "rbxassetid://".. Tables.IdleAnimations
						end
					end
					Tool.Unequipped:Connect(function()
						LoadIdleAnimation:Stop()
					end)
				end)
			end
		end
		Character.ChildAdded:Connect(ToolHandler)
	end
end
return ToolSystem

1 Like

It is best to stop the old animation before starting a new one.