#Flood that damages players inside (region detection?)

1 messages · Page 1 of 1 (latest)

proven schooner
#

This is my code so far:

local flood = script.Parent
local debounce = false
local cooldown = 1
local damage = 10

flood.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")

if debounce == false  then
    debounce = true
    if humanoid then
        humanoid.Health -= damage
    end
    task.wait(cooldown)
    debounce = false
end    

end)

I already got the tween service and everything so that the flood moves up. However, the issue here is the touched event not working because the flood part has can collide set to false. So, how should I tackle this? Should I use workspace:GetPartsInBox()? How do I make it so that the player inside the flood region takes 10 damage per second?

robust relic
#

you can use workspace:GetPartsInPart

proven schooner
#

how do i use it 😭

robust relic
#

you can read the documentation

proven schooner
#

yes i tried using get parts in part but idk how to exacly apply it to my code. im still a beginner

robust relic
#

so the function's arguments are a part and overlapparams and it returns an array of parts

proven schooner
#

ok actually ill try doing it and ill post what i have

robust relic
#

overlapparams is optional

proven schooner
#

ok

robust relic
#

you can then loop through the parts and see if any of them are part of a character

#

for the debounce i don't think you should use one boolean variable though

#

because that debounce will apply to every single person

proven schooner
#

lowkey this is harder than i thought

#

local flood = script.Parent
local debounce = false
local cooldown = 1
local damage = 10

local overlaps = {}

while true do
workspace:GetPartsInPart(flood, overlaps)
local humanoid = overlaps.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health -= damage
end
task.wait(cooldown)
end

bronze ploverBOT
#

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

proven schooner
#

i have no idea how to apply GetPartsinPart()

robust relic
#

you can just use your old code but instead of checking the touched part, check every part in the loop

proven schooner
agile spindle
bronze ploverBOT
#

studio** You are now Level 3! **studio

ripe stratus
proven schooner
#

Update: I figured out how to use GetPartBoundsinBox, but I am simply printing whats inside the flood every second:

local flood = script.Parent
local debounce = false
local cooldown = 1
local damage = 10

local function GetPartsTouching(Part:BasePart)
local filter = OverlapParams.new()

filter.FilterDescendantsInstances = {Part}
filter.FilterType = Enum.RaycastFilterType.Exclude

local cf, size = Part.CFrame, Part.Size
return workspace:GetPartBoundsInBox(cf, size)

end

while task.wait(1) do
print(GetPartsTouching(flood))
end

proven schooner
#

Solved!!! Heres the code:

local flood = script.Parent
local debounce = false
local cooldown = 1
local damage = 5

local function GetPartsTouching(Part:BasePart)
local filter = OverlapParams.new()

filter.FilterDescendantsInstances = {Part}
filter.FilterType = Enum.RaycastFilterType.Exclude

local cf, size = Part.CFrame, Part.Size
return workspace:GetPartBoundsInBox(cf, size)

end

while true do
local touchingParts = GetPartsTouching(flood)
for _, part in ipairs(touchingParts) do
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if character and player then
local humanoid = character:FindFirstChildOfClass("Humanoid")

        if debounce == false then
            debounce = true
            if humanoid then
                humanoid:TakeDamage(damage)
            end
            task.wait(cooldown)
            debounce = false
        end
    end
end
task.wait(.5)

end

#

i love ipairs bro this solved everything

#

I checked the player's health every 1 tenth of a second and its damaging by the correct amount of 5

#

The touched event is only useful if you want the player to instantly die

#

SOLVED