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
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.....