Help with lightsaber block script

making a lightsaber block function in a module
the animation plays but it doesn’t stop although it prints it stopped here is the script

function lightsaber.Block(player)
	
	local animation = game.ServerStorage.Animations.Blocks.Block:Clone()
	local hum = player.Character:FindFirstChild("Humanoid")
	local animator = hum:WaitForChild("Animator") or Instance.new("Animator", hum)
	local animtoplay = animator:LoadAnimation(animation)

	if isequipped then
		if player.Character.Humanoid:GetAttribute("Blocking", true) then
			player.Character.Humanoid:SetAttribute("Blocking", false)
			if player.Character.Humanoid:GetAttribute("Blocking") == false then
				animtoplay:Stop()
				animtoplay:Destroy()
				print("Blocking Is False")
			end
		else
			player.Character.Humanoid:SetAttribute("Blocking", true)
			print("Blocking IS True")
			animtoplay:Play()
		end
	else
		return
	end
end

here is what it does in game

1 Like

I’m pretty sure every time you run the function it creates a new animation. This would mean that unblocking would just delete the animation created in that calling of the function, not the one created before when the block started.

2 Likes

Store the animation instance: Add an attribute to the humanoid to store the animation instance.

Checking For Blocking: Change the check to directly look for Blocking without setting it to true in the condition.

Potential Issue: make sure the animtoplay:Stop() is effectively referenced before destroying it.

2 Likes

I just tried this but it still doesn’t seem to work ty for the reply though

1 Like