Animations Not Changing

Hello, so, every time the outfit changes i need the idle animation to start, how ever the script i have made only does what it needs to do the first time, other times it is not changing the playing animation, even thought it prints that it is

local Number = script.Parent.Outfits.OutfitNumber
local RE = game:GetService("ReplicatedStorage"):WaitForChild("OpenWardrobe")
local closingRE = game:GetService("ReplicatedStorage"):WaitForChild("ApplyAvatar")
local sp = 1

local function Start()
	local plr = script.Parent.Parent.Parent
	local backpack = plr.Backpack.AvatarOutfits:GetChildren()
	local avatar = game.Workspace.MainMenu.DummysFolder.Clothing:WaitForChild(plr.Name)
	if Number.Value == "0" then
		avatar.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(plr.UserId))
		local description = game.Players:GetHumanoidDescriptionFromUserId(plr.UserId)
		local idleId = description.IdleAnimation
		print(idleId)
		for i,x in pairs(script.Parent.Pages.Animations.ScrollingFrame:GetChildren()) do
			if x:IsA("TextButton") then
				if tostring(idleId) == tostring(x.Idle.Value) then
					print("Found A Match "..x.Idle.Value)
					local humanim = avatar.Humanoid:LoadAnimation(x.Animation)
					humanim:Play()
					humanim.Looped = true
					humanim:AdjustSpeed(sp)
				end
			end
		end
	else
		for i,v in pairs(backpack) do
			if v.Name == Number.Value then
				avatar.Humanoid:ApplyDescription(v.Humanoid:GetAppliedDescription())
				local description = v.Humanoid:GetAppliedDescription()
				local idleId = description.IdleAnimation
				print(idleId)
				for i,x in pairs(script.Parent.Pages.Animations.ScrollingFrame:GetChildren()) do
					if x:IsA("TextButton") then
						if tostring(idleId) == tostring(x.Idle.Value) then
							print("Found A Match "..x.Idle.Value)
							local humanim = avatar.Humanoid:LoadAnimation(x.Animation)
							humanim:Play()
							print("Playing Animation")
							humanim.Looped = true
							humanim:AdjustSpeed(sp)
						end
					end
				end
			end
		end
		for i,v in pairs(plr.Backpack.AvatarOutfits.DeleteButtons:FindFirstChild(Number.Value):GetChildren()) do
			for i,c in pairs(v:GetChildren()) do
				for i,x in pairs(script.Parent.Pages.Accessories:GetChildren()) do
					if x:IsA("Frame") then
						if c.Name == x.Name then
							c.Parent = x.Wearing
						end
					end
				end
			end
		end
	end
end

Number:GetPropertyChangedSignal("Value"):Connect(Start)
RE.OnServerEvent:Connect(function(player)
	if player.Name == script.Parent.Parent.Parent.Name then
		Start()
		RE:FireClient(player)
	end
end)

if you have any questions please do ask

It doesn’t look like you have any code that stops your previous animation. If it’s looped as well, it seems that some animations have a bigger priority than some of the others. Try adding in code that stops your current idle animation and then plays the new idle animation that you load when you switch outfits.

Edit: I’d also like to add that you should only load the animation once, for there’s a finite amount times Roblox allows a humanoid to load animations. loading all the animations before you run your code and then play/stop them when they meet your specified parameters.

thanks a lot, i didn’t know i needed to stop animations before playing another one