So basically I want to make player deal damage continuously when they touch the part.
However, using the touched function.
script.parent.Touched:Connect(function(part)
Local player = part.Parent
Local humanoid = player.Humanoid
humanoid.Health -= 1
end)
The player will only get detected for a few times and deal ~ 4-7 damage
Any ways to make the part keep detecting if the player still on the part and damage the player continuously?
Thank you
you need to use a debounce more info about it here if you want to understand it more
local db = false
local DB_TIME = 4.5 -- 4.5 seconds
script.parent.Touched:Connect(function(part)
if db then return end -- makes it not run
db = true
Local player = part.Parent
Local humanoid = player.Humanoid
humanoid.Health -= 1
wait(DB_TIME) -- waits a time then turns off the debounce
db = false
end)
Okay here im pretty sure this is what you wanted you can also read more about region3 on the roblox wiki like @THECOOLGENERATOR said
local DamageTime = 1 -- amount of time until next check
local DamageAmount = 5 -- how much damage per check
local Part = script.Parent -- the part
local function GivePlayersInArea()
local region = Region3.new(Part.CFrame.p-Part.Size/2,Part.CFrame.p+Part.Size/2)
local parts = workspace:FindPartsInRegion3(region,nil,math.huge) -- gives all the part in the region3 i picked math.huge so that means we can have no limit on how many parts can be in the region
local tab = {}
for i,v in pairs(parts) do
if v.Parent then
if game.Players:GetPlayerFromCharacter(v.Parent) and not table.find(tab,v.Parent) then
table.insert(tab,v.Parent) -- puts the players character inside the table
end
end
end
return tab
end
while wait(DamageTime) do
for i ,v in pairs(GivePlayersInArea()) do
v.Humanoid:TakeDamage(DamageAmount) -- takes damage
end
end
I tried one for my own script but it do sent like keep doing damage but it does reliably how do i check copiously if touched I will try simply turning off and on touch to cheese it but if that dosent work pls respound if it does still respound because i dont like that solution