Block Animation plays, but does not stop

  1. What do you want to achieve? Keep it simple and clear!
    When you press F, you will be able to block, and when you let go of F, it will stop blocking.

  2. What is the issue? Include screenshots / videos if possible!
    The function below is successfully recieving when F is pressed and let go like it is supposed to. When you press F, it will create a BoolValue under the player’s workspace model (and it works), and then the function will use that to detect if the player is currently blocking. When you let go of F, the BoolValue then destroys itself (as it should), but the animation keeps playing.

The function (inside of a ModuleScript):

local blockdb = false

function cSet:Block(plr, animator, prevWS)
	if blockdb == false then
		blockdb = true
		print("Block Request Recieved")
		
		local blockAnimation
		blockAnimation = animator:LoadAnimation(game.ReplicatedStorage.Combat.Animations.Block["1"])
		
		print("Anim Loaded. ", blockAnimation.Name)
		if plr:FindFirstChild("Block") == nil then
			print("Block Not Found, Creating In ", plr.Name)
			local block = Instance.new("BoolValue")
			block.Name = "Block"
			block.Parent = plr
			print("Block: ", block.Name)
		else
			print("Destroying Block In ", plr.Name)
			plr.Block:Destroy()
		end
		
		if plr:FindFirstChild("Block") ~= nil then 
			print("Block Found, setting Block Animation Priority To Action4 and Playing")
			print("Block Animation: ", blockAnimation.Name)
			blockAnimation.Priority = Enum.AnimationPriority.Action4
			blockAnimation:Play()
		else
			print("Block Not Found, Assuming Stop Block, Stopping Anim")
			blockAnimation:Stop()
			task.wait(cSet.DashCooldown)
		end

		blockdb = false
	end
end

Video w/ Outputs:

When F is pressed:

When F is released:
image

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked on a few forums and used :Stop(), :Pause() and :Destroy() as well as trying a couple of other things, however, none of them have worked.
local blockdb = false
local blockAnimation

function cSet:Block(plr, animator, prevWS)
	if blockdb == false then
		blockdb = true
		print("Block Request Received")
		
		if not blockAnimation then
			blockAnimation = animator:LoadAnimation(game.ReplicatedStorage.Combat.Animations.Block["1"])
		end

		if plr:FindFirstChild("Block") == nil then
			print("Block Not Found, Creating In ", plr.Name)
			local block = Instance.new("BoolValue")
			block.Name = "Block"
			block.Parent = plr
			print("Block: ", block.Name)
			
			blockAnimation.Priority = Enum.AnimationPriority.Action4
			blockAnimation:Play()
		else
			print("Destroying Block In ", plr.Name)
			plr.Block:Destroy()
			
			if blockAnimation.IsPlaying then
				blockAnimation:Stop()
			end
		end
		
		blockdb = false
	end
end

it is … sonic_848
“Its probably cz you’re loading a new animation track every time you call the function”

Not sure if this will fix that but, I think that is the problem also.

Its probably cz you’re loading a new animation track every time you call the function. To cancel the anim why don’t you loop through the animators playing tracks, find the block anim track, then stop it

1 Like

How did your post get positioned over mine :skull:

My comment was there 1st … I went back to add what you ended up saying. Then while doing that saw yours pop up. So I just quoted you.

Edit: I probably posted a millisecond later and on my end it didn’t load everything so I saw mine first… Mb @2112Jay

This was one of the only things I have not tried, and it works. Thank you so much!

1 Like

Took the time to script that out …
I got robbed … :rofl:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.