local Cooldown = script.Parent:WaitForChild("Cooldown")
local function Attack(hit)
if Cooldown.Value == 1 then
return
elseif hit.Parent.Parent:FindFirstChild("Humanoid") or hit.Parent:FindFirstChild("Humanoid") then
Cooldown.Value = 1
end
if hit.Parent.Parent:FindFirstChild("Humanoid") or hit.Parent:FindFirstChild("Humanoid") then
print("yes")
--Animation
local punchAnimation = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.Bandit_Attack)
punchAnimation:Play()
punchAnimation.KeyframeReached:Connect(function(keyframeName)
if keyframeName ~= "Damage" then
return
end
--Creates hitbox and positions it
local hitbox = Instance.new("Part")
hitbox.Size = Vector3.new(3, 3, 3)
hitbox.CanCollide = false
hitbox.Transparency = 0.8
hitbox.Color = Color3.new(1, 0, 0)
hitbox.Parent = script.Parent
hitbox.Name = "DummyAttackHitbox"
local weld = Instance.new("Weld")
weld.Parent = script.Parent.HumanoidRootPart
weld.Part0 = hitbox
weld.Part1 = script.Parent.HumanoidRootPart
weld.C1 = CFrame.new(0,0,-2)
--Punch Output
local Touched = script.Parent.DummyAttackHitbox.Touched:connect(function(hit)
if hit.Name == "PlayerHealthHitbox" then
print("Yes")
hit.Parent.Humanoid.Health -= 10
end
end)
--End of Animation
task.wait(0.1)
Touched:Disconnect()
hitbox:Destroy()
task.wait(3)
Cooldown.Value = 0
end)
end
end
script.Parent.AttackRadius.Touched:Connect(Attack)
It prints out “yes” four times, I only want it to attack it once.