Confused with BlockingSystem

This is probably my first time ever making an actual proper blocking system and the problem I’m having is the animation does not stop when the event is fired again with the bool false. But the NoRun and Blocking Values are destroyed from the players character but no animation is played? Why is that. Code is below. Also, how do people implement with tick a cd to prevent block spamming? so if the player had “Attacking” in his Character an x amt of seconds ago he cant block

EDIT: Thought abt the x amt of thing and thoughtr I should make a value that updates the seconds/holds the time an attack was thrown

Code: (Sorry for a super long question)

BlockingEvent.OnServerEvent:Connect(function(Player, Action, Type, Bool)
	local toolName = Character:FindFirstChildOfClass("Tool") and Character:FindFirstChildOfClass("Tool").Name
	local blockAnim = Humanoid:LoadAnimation(AnimsFolder:FindFirstChild(toolName).Block)

	if Action then
		if Type == "Magic" then
			if Bool == true then
				mBlock(Character)
				-- Handle magic blocking value
				-- e.g., Player.MagicBlockingValue = 10
			else
				Player.Character.NoRun:Destroy()
				Player.Character.ShieldBlocking:Destroy()
				-- Handle magic blocking value reset or cleanup
				-- e.g., Player.MagicBlockingValue = 0
			end
		elseif Type ~= "Magic" and Bool == true then
			blockAnim:Play()

				Block(Character)
				-- Handle regular blocking value
				-- e.g., Player.RegularBlockingValue = 5

		elseif Bool == false then
			blockAnim:Stop()
			Player.Character.NoRun:Destroy()
			Player.Character.Blocking:Destroy()
			-- Handle any other necessary cleanup for normal blocking
		end
	end
end)
1 Like

You’re recreating blockAnim every time the event is being fired which means it will keep playing forever. Move it out of your OnServerEvent and only play/stop the animation when the BlockingEvent has been fired

local toolName = Character:FindFirstChildOfClass("Tool") and Character:FindFirstChildOfClass("Tool").Name
local blockAnim = Humanoid:LoadAnimation(AnimsFolder:FindFirstChild(toolName).Block)

BlockingEvent.OnServerEvent:Connect(function(Player, Action, Type, Bool)
	if Action then
		if Type == "Magic" then
			if Bool == true then
				mBlock(Character)
				-- Handle magic blocking value
				-- e.g., Player.MagicBlockingValue = 10
			else
				Player.Character.NoRun:Destroy()
				Player.Character.ShieldBlocking:Destroy()
				-- Handle magic blocking value reset or cleanup
				-- e.g., Player.MagicBlockingValue = 0
			end
		elseif Type ~= "Magic" and Bool == true then
			blockAnim:Play()

				Block(Character)
				-- Handle regular blocking value
				-- e.g., Player.RegularBlockingValue = 5

		elseif Bool == false then
			blockAnim:Stop()
			Player.Character.NoRun:Destroy()
			Player.Character.Blocking:Destroy()
			-- Handle any other necessary cleanup for normal blocking
		end
	end
end)```
1 Like

I agree with this. Also, animations that are played locally on the humanoid will be replicated to the server by default, so it’s not required to play it serverside.

I tried this, no the animations arent played locally (I decided to play blocking on server) and handle stuns on client

Also the animations don’t even play now so that’s the problem
The block is supposed to work for multiple tools not one