local tool = script.Parent
local hitboxSize = Vector3.new(5, 1, 5)
local damageEvent = game.ReplicatedStorage.Events.DamageEvent
local damageAmount = 5
local humanoidAttacker = game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidrootpart = character:WaitForChild(“HumanoidRootPart”)
local humanoid = character:WaitForChild(“Humanoid”)
local anim = tool.SwordAnimations:WaitForChild(“Block”)
local animator = humanoid:FindFirstChildOfClass(“Animator”)
local function SwordSlashes()
local numSlashes = 0
local lastSlashTime = tick()
local slashCooldown = 0
local isPlayingAnimation = false
local function Slash()
if numSlashes >= 5 or isPlayingAnimation then
return
end
local timeSinceLastSlash = tick() - lastSlashTime
if timeSinceLastSlash < slashCooldown then
return
end
if timeSinceLastSlash > 2 and numSlashes > 0 then
numSlashes = 0
wait(3)
end
local slashAnimName = "Slash" .. (numSlashes + 1)
local slashAnim = tool.SwordAnimations:WaitForChild(slashAnimName)
local slash = animator:LoadAnimation(slashAnim)
if not isPlayingAnimation and not slash.IsPlaying then
isPlayingAnimation = true
slash:Play()
slash:AdjustSpeed(1.3)
slash.Stopped:Wait()
numSlashes = numSlashes + 1
lastSlashTime = tick()
isPlayingAnimation = false
local hitbox = Instance.new("Part")
hitbox.Name = "Hitbox"
hitbox.Anchored = true
hitbox.Size = hitboxSize
hitbox.CanCollide = false
hitbox.Transparency = 0.5
hitbox.CFrame = humanoidrootpart.CFrame * CFrame.new(0, 0, -3)
hitbox.Parent = workspace
for _, humanoid in ipairs(workspace:GetDescendants()) do
if humanoid:IsA("Humanoid") and humanoid.Parent ~= character then
local distance = (humanoid.RootPart.Position - hitbox.Position).Magnitude
if distance < hitboxSize.magnitude / 2 then
damageEvent:FireServer(humanoid, damageAmount, humanoidAttacker)
end
end
end
hitbox:Destroy()
end
end
spawn(function()
while true do
wait(0.1)
local timeSinceLastSlash = tick() - lastSlashTime
if timeSinceLastSlash > 1 and numSlashes > 0 then
numSlashes = 0
end
end
end)
return Slash
end
local slashAction = SwordSlashes()
tool.Activated:Connect(slashAction)