so below is my attack module for the better tree plugin, I need help making it so that it repeats itself, i.e while the Can attack state is true it loops through the script
local npchitboxmodule = require(game.ReplicatedStorage.Modules.NpcHitbox)
local task = {}
local SUCCESS,FAIL,RUNNING = 1,2,3
-- Any arguments passed into Tree:run(obj) can be received after the first parameter, obj
-- Example: Tree:run(obj,deltaTime) - > task.start(obj, deltaTime), task.run(obj, deltaTime), task.finish(obj, status, deltaTime)
-- Blackboards
-- objects attached to the tree have tables injected into them called Blackboards.
-- these can be read from and written to by the tree using the Blackboard node, and can be accessed in tasks via object.Blackboard
--
function task.start(obj)
print("swtartingatattack")
local Blackboard = obj.Blackboard
end
function task.finish(obj, status)
local Blackboard = obj.Blackboard
end
function task.run(obj)
local Blackboard = obj.Blackboard
local target = obj.Target
if target then
local TargetHp = target.HumanoidRootPart
local targetHumanoid = target:FindFirstChild("Humanoid")
local zombiehp = obj.model.HumanoidRootPart
local zombieHumanoid = obj.model.Humanoid
local CombatNum = zombieHumanoid.Parent:GetAttribute("CombatNum")
local m1cooldown = false
local hitboxModule = require(game:FindFirstChild("ReplicatedStorage").Modules.HitboxModule)
local module = require(game:GetService("ReplicatedStorage").Modules.CombatSystemModule)
local rs = game:GetService("ReplicatedStorage")
local bloodvfx = rs:WaitForChild("BloodVfx")
if targetHumanoid and targetHumanoid.Health > 0 then
if targetHumanoid.Parent:GetAttribute('IsBlocking') == true then
CombatNum = 5
for i,v in game:GetService("ReplicatedFirst").Animations.FistM1:GetChildren() do
if tonumber(v.Name) == CombatNum and m1cooldown == false then
m1cooldown = true
local FistCombat = zombieHumanoid:LoadAnimation(v)
FistCombat:Play()
FistCombat:AdjustSpeed(0.8)
if CombatNum == 5 then
hitboxModule.Hitbox(script.Parent, CFrame.new(0,0,-2.5), 7, 8,100,"Yes", bloodvfx)
print("5th m1")
wait(1)
m1cooldown = false
else
wait(1)
m1cooldown = false
end
end
end
end
if targetHumanoid.Parent:GetAttribute('IsBlocking') == false then
for i,v in game:GetService("ReplicatedFirst").Animations.FistM1:GetChildren() do
if tonumber(v.Name) == CombatNum and m1cooldown == false then
m1cooldown = true
--script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position,player.Character.HumanoidRootPart.Position)
local FistCombat = zombieHumanoid:LoadAnimation(v)
FistCombat:Play()
FistCombat:AdjustSpeed(0.8)
zombieHumanoid.Parent:SetAttribute("CombatNum", zombieHumanoid.Parent:GetAttribute("CombatNum") + 1)
if CombatNum > 5 then
zombieHumanoid.Parent:SetAttribute("CombatNum", 1)
end
--hitboxModule.Hitbox()
wait(0.3)
if CombatNum == 5 then
hitboxModule.Hitbox(zombieHumanoid.Parent, CFrame.new(0,0,-2.5), 7, 8,100,"Yes", bloodvfx)
print("5th m1")
wait(1)
m1cooldown = false
else
hitboxModule.Hitbox(zombieHumanoid.Parent, CFrame.new(0,0,-2.5), 7, 8,50,"no", bloodvfx)
wait(1)
m1cooldown = false
end
end
end
end
end
end
return SUCCESS
end
return task