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

Region3 stacking damage each time it's triggered?

Asked by 1 year ago

I have this explosion hitbox using region3, when the player touches it, its supposed to deal 3 damage to them. But for some reason, the damage is more than 3, and keeps going up each time the player gets damage. I tried debounce, but that didn't seem to work. Can anyone help me?

local part = script.Parent 

local region = Region3.new(part.Position - part.Size/2, part.Position + part.Size/2)
local db = false
while true do 
    if not db then
    local parts = workspace:FindPartsInRegion3(region, part)
    for i, part in pairs(parts) do
        local char = part.Parent
        local player = game.Players:GetPlayerFromCharacter(part.Parent)
        if player then 
                char.Humanoid.Health -= 3
            print(player.Name)
        end
        end


    wait(1)
        db = false
        end
end 

1 answer

Log in to vote
2
Answered by
imKirda 4491 Moderation Voter Community Moderator
1 year ago

remove the debounce, that's unacceptable, the real reason why he gets a lot of damage is because you subtract 3 health for every limb of the character, :FindPartsInRegion3 includes all the player limbs and accessories.

to solve this you can create container into which you are going to put players which have already been damaged in any limb, then, before damaging them with next limb you are going to check if the player is not already in the container, if he is then you won't damage him since he has already been damaged, otherwise put him into the container and deal 3 damage:.

local part = script.Parent 

local region = Region3.new(part.Position - part.Size/2, part.Position + part.Size/2)

while not false do
    local parts = workspace:FindPartsInRegion3(region, part)
    local already_damaged_players = {}

    for i, part in pairs(parts) do
        local char = part.Parent
        local player = game.Players:GetPlayerFromCharacter(part.Parent)

        -- table.find = hmm, i will find `player` in `already_damaged_players`,
        -- if he is there then don't run the `then` code!!!!
        if player and not table.find(already_damaged_players, player) then
            -- put the `player` into `already_damaged_players` since we will
            -- damage him on the next line of code
            table.insert(already_damaged_players, player)
            char.Humanoid.Health -= 3
            print(player.Name)
        end
    end

    task.wait(1) -- task.wait!!!!!!!! ):< (no strong reason why though)
end 

and nowadays Region3 is deprecated!!!!! roblox wants you to use Workspace:GetPartBoundsInBox, the choice is yours.....

0
Thanks for your help! I can't get GetPartBoundsInBox to work for the life of me, so I'll use region3 for the time being. Uniplier 83 — 1y
0
Well it turns out region3 doesn't even work for the use I had in mind. I have to switch to GetPartBoundsInBox. Sorry for wasting your time. Uniplier 83 — 1y
0
hmmmmmmmmmmmmmmmmmmm i guess if you beg me so much i might consider forgiving you............. imKirda 4491 — 1y
0
:sob: Uniplier 83 — 1y
Ad

Answer this question