So here I have a big part (50x50x50 studs), and I put this damage script inside it:
local debounce = false
local cooldown = 0.25
part.Touched:Connect(function(hit)
if hit.Parent.Name == character.Name then return end
if hit.Parent:FindFirstChild("Humanoid") then
if table.find(hits, hit.Parent) then return
else
if not debounce then
debounce = true
hit.Parent:WaitForChild("Humanoid"):TakeDamage(10)
wait(cooldown)
debounce = false
end
end
end
end)
The problem, is that I have to actually move while being inside the part to get damaged.
What I want to happen is that I keep getting damaged even while idling inside it.
How can I make that happen? thanks a lot for any help!
You should use game.Workspace:GetPartsInPart(part) to achieve this as Touched isn’t very reliable
while true do
wait()
for i,v in pairs(game.Workspace:GetPartsInPart(part)) do
if hit.Parent.Name == character.Name then continue end
if hit.Parent:FindFirstChild("Humanoid") then
if table.find(hits, hit.Parent) then continue
else
if not debounce then
debounce = true
hit.Parent:WaitForChild("Humanoid"):TakeDamage(10)
task.wait(cooldown)
debounce = false
end
end
end
end
end
Sorry I forgot to mention but put a break after turning off debounce, it’s iterating over every part of the character, damaging the player for those parts
part.Touched:Connect(function(hit)
task.spawn(function()
while wait() do
for i, v in pairs(workspace:GetPartsInPart(fireBreath)) do
if hit.Parent.Name == character.Name then continue end
if hit.Parent:FindFirstChild("Humanoid") then
if table.find(hits, hit.Parent) then continue
else
if not debounce then
debounce = true
combatModule.Hit(player, hit, sounds:WaitForChild("Hit"), values:WaitForChild("DefaultDamage").Value * skillConfig:WaitForChild("DamageMulti").Value)
task.wait(cooldown)
debounce = false
break
end
end
end
end
end
end)
end)
task.spawn(function()
while task.wait() do -- better to use a timed loop
for i, hit in pairs(workspace:GetPartsInPart(part)) do
if hit.Parent.Name == character.Name then continue end
if hit.Parent:FindFirstChild("Humanoid") then
if table.find(hits, hit.Parent) then continue
else
if not debounce then
debounce = true
combatModule.Hit(player, hit, sounds:WaitForChild("Hit"), values:WaitForChild("DefaultDamage").Value * skillConfig:WaitForChild("DamageMulti").Value)
task.wait(cooldown)
debounce = false
break
end
end
end
end
end
end)
local debounce = time()
local cooldown = 0.25
task.spawn(function()
while task.wait() do
local breakk = true
for i, hit in pairs(workspace:GetPartsInPart(part)) do
if hit.Parent.Name == character.Name then
if hit.Parent:FindFirstChildOfClass("Humanoid") then
if time() - debounce > cooldown then
debounce = time()
combatModule.Hit(player, hit, sounds:WaitForChild("Hit"), values:WaitForChild("DefaultDamage").Value * skillConfig:WaitForChild("DamageMulti").Value)
end
breakk = false
end
end
end
if breakk then
break
end
end
end)
local debounce = false
local cooldown = 0.25
local threads = {}
local characterDetected = {}
-- You can use the more accurate but performance heavy overlapparams or the simple vector within cframe
local function detect()
end
-- Your damage function
local function bleed()
end
--Start damage
part.Touched:Connect(function(hit)
--Confirm it's not the same character, you don't want to be stacking damage on the same character
local findCharacter = characterDetected[character]
if findCharacter then
return
end
local findThread = threads[character]
if findThread then
task.cancel(findThread)
end
thread = task.spawn(bleed())
end)
--End damage
part.TouchEnded:Connect(function(hit))
-- You will need to do the same when character dies or player leaves the server; to prevent memory leak.
local findCharacter = characterDetected[character]
if findCharacter then
characterDetected[character] = nil
end
local findThread = threads[character]
if findThread then
task.cancel(findThread)
end
end)