#Hitboxes not working when in a for loop

1 messages · Page 1 of 1 (latest)

broken ermine
#
local Debris = game:GetService("Debris")

local cd = false

local touch = false

script.Parent.Activated:Connect(function()
    if cd == true then return end
    cd = true

    local player = script.Parent.Parent

    local animation = script.Animation
    local humanoid = script.Parent.Parent.Humanoid

    local animTrack = humanoid:LoadAnimation(animation)

    animTrack:Play()
    task.wait(0.2)

    script.Sound:Play()

    for i = 1, 75 do

        local hittable = {}

        local hitbox = Instance.new("Part", workspace.Hitboxes)
        hitbox.Size = Vector3.new(6,8,18)
        hitbox.CFrame = player.HumanoidRootPart.CFrame * CFrame.new(0,-2,-12)
        hitbox.Anchored = true
        hitbox.CanCollide = false
        hitbox.Transparency = 1

        task.wait()
        game.ReplicatedStorage.HitBox:FireAllClients(hitbox)

        hitbox.Touched:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") and hittable[hit.Parent] ~= true and hit.Parent ~= player then
                hittable[hit.Parent] = true
                hit.Parent.Humanoid.Health -= 12
            end
        end)

        Debris:AddItem(hitbox, 0.1)

        task.wait(0.025)
    end

    task.wait(30)
    cd = false
end)
#

this is in a server script in a tool

#

it only stops working after using the tool 3 - 4 times

digital raptor
#

hitboxes with touched event?

pastel compass
#

First, why are you creating 75 hit boxes, second, firing all clients that many times in such a short period is slightly questionable, and lastly, could you provide the output when you run it?

broken ermine
velvet sundialBOT
#

studio** You are now Level 1! **studio

broken ermine
digital raptor
# broken ermine im kinda new to scripting is there any better ways to do it?

Video Description:
In this video I cover the topic of Spatial Query and OverlapParams, and how you can use various methods to detect when objects are within a specified hitbox. This is extremely useful for creating hitboxes for special abilities or anything like that when .Touched just doesn't cut it. I know I said I was going to start the shop ...

▶ Play video
#

you coul also use raycasts

broken ermine
#

oh ok ty

digital raptor
#

thats kind advanced