Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get my sword to hit multiple enemies at a time?

Asked by
tjtorin 172
4 years ago

My sword can only hit one enemy at a time because my script checks if HitDelay is true and if it is, do not deal damage. HitDelay is false until the player presses there right mouse button.

function Blow(Part)
    local PartTouched
    local HitDelay = false
    PartTouched = Part.Touched:connect(function(Hit)
        if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped or HitDelay then
            return
        end
        local RightArm = (Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand"))
        if not RightArm then
            return
        end
        local RightGrip = RightArm:FindFirstChild("RightGrip")
        if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
            return
        end
        local character = Hit.Parent
        if character == Character then
            return
        end
        local humanoid = character:FindFirstChild("Humanoid")
        if not humanoid or humanoid.Health == 0 then
            return
        end
        local player = Players:GetPlayerFromCharacter(character)
        if player and (player == Player or IsTeamMate(Player, player)) then
            return
        end

        HitDelay = true
        local TotalDamage = Damage
        DealDamage(character, TotalDamage)
        local Now = tick()
        local SwingAnimations = ((Humanoid.RigType == Enum.HumanoidRigType.R6 and {Animations.R6LeftSlash, Animations.R6RightSlash, Animations.R6SideSwipe})
        or (Humanoid.RigType == Enum.HumanoidRigType.R15 and {Animations.R15LeftSlash, --[[Animations.R15RightSlash,]] Animations.R15SideSwipe}))
        local Animation = SwingAnimations[math.random(1, #SwingAnimations)]
        wait(Animation.Duration - .1)
        HitDelay = true
    end)
end
1
You could always just make a table and insert the humanoids you hit on that swing and then reset the table every swing. Mr_Pure 129 — 4y

Answer this question