Blocking System NPC

I have a script for blocking but I don’t know how to implement it into NPCs. If someone knows how and could give me an example with the “Drooling Zombie” NPC, that would be a big help.

image

image

Blocking:

local player =  game.Players.LocalPlayer
local uis =  game:GetService("UserInputService")

local blockingAnim =  script:WaitForChild("BlockingAnim")





local CD = 1

local debounce = false

local BlockingRemote =  game.ReplicatedStorage.BlockRemote.Blocking
local RemoveBlocking = game.ReplicatedStorage.BlockRemote.RemoveBlocking

local char = player.Character or player.CharacterAdded:Wait()

local hum = char:WaitForChild("Humanoid")

local gaurdingAnimation =  hum:LoadAnimation(blockingAnim)



uis.InputBegan:Connect(function(input,Typing)
	if not Typing then
		if input.KeyCode == Enum.KeyCode.F and debounce == false then
			if char:FindFirstChild("BlockBreak") == nil  and char:FindFirstChild("Stun") == nil  and char:FindFirstChild("eStun") == nil then
				debounce = true
				BlockingRemote:FireServer()
				game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 65}):Play()
				hum.WalkSpeed = 7
				gaurdingAnimation:Play()
				wait(CD)
				debounce = false

			end

		end
	end
end)

uis.InputEnded:Connect(function(input,Typing)
	if input.KeyCode == Enum.KeyCode.F then
		RemoveBlocking:FireServer()
		game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 70}):Play()
		gaurdingAnimation:Stop()

		hum.WalkSpeed = 15

	end
end)

RemoveBlocking.OnClientEvent:Connect(function()
	RemoveBlocking:FireServer()
	game.TweenService:Create(workspace.CurrentCamera,TweenInfo.new(.3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{FieldOfView = 70}):Play()
	gaurdingAnimation:Stop()

	hum.WalkSpeed = 15

end)

Block:

local Block =  game.ReplicatedStorage.BlockRemote.Blocking
local Remove = game.ReplicatedStorage.BlockRemote.RemoveBlocking

Block.OnServerEvent:Connect(function(plr)
	local char = plr.Character
	
	local BlockingValue = Instance.new("BoolValue",char)
	BlockingValue.Name =  "IsBlocking"

end)

Remove.OnServerEvent:Connect(function(plr)
	for i,v in pairs(plr.Character:GetChildren())do
		if v.Name == "IsBlocking" then
			v:Destroy()
		end
	end
end)

That’s all the information that I have so if you know how to fix this it would be a big help!

I’ve actually done this in my game and it’s fairly simple. Just make them block in a heartbeat function as long as they are allowed to