Reduce lag when playing animations?

I have an animation handler that checks which animation is supposed to play next, but it lags a ton.
When I remove this handler, it lags a lot less.

It there a way to get the functionality of the block handler, but reduce the lag?

Also why is the lag happening??

here is the code

local function DetectBlock()
	if hold and equipped  == true then
		if hit1 == true then
			stopBlock()
			if debound31 == false then
				Block1:Play()
			elseif debound31 == true then
				BlockSound:Play()
				Special31:Play()
			end
			wait(0.15)
			if hold == true then
				Idle1:Play()
			end
		elseif hit2 == true then
			BlockSound:Play()		
			stopBlock()
			Block2:Play()
			wait(0.15)
			if hold == true then
				Idle2:Play()
			end
		elseif hit3 == true then
			BlockSound:Play()
			stopBlock()
			Block3:Play()
			wait(0.15)
			if hold == true then
				Idle3:Play() 
			end
		end
	end
end

The IdleAnimation is the last keyframe of the animation from switching. How do I make this less laggy its kind of unplayable???

1 Like