If i’m being completely honest, you could use a module called ZonePlus basically all this module does is simplify Region3, what Region3 does is it allows you to check players in an Area, basically by using 2 different position’s, but with ZonePlus, you could instead turn a Part into a Region3, which makes it easier to detect who is inside the Region.
You could also use something called :GetPartBoundsInRadius which is basically just searching a circular/spherical area instead of a cubic one.
I’m going to create a script without it though, first of i’ll be using :GetTouchingParts, and if you’d want tick damage, you’d make a debounce table. (a table with the names of players who are currently on cooldown from taking damage)
local RunService = game:GetService("RunService") -- getting the runservice which allows loops
local part = script.Parent
local debounce = {}
local cooldownTime = 1 -- the time that elapses before the play takes tick damage again
function checkPlayers()
local d
d = part.Touched:Connect(function() -- prevents the function from running multiple times
d:Disconnect()
end)
for _, v in pairs(part:GetTouchingParts()) do -- loops through touching
local h = v.Parent:FindFirstChildOfClass("Humanoid")
if h then -- if humanoid found then
if debounce[h.Parent.Name] then
continue
else
debounce[h.Parent.Name] = { -- player inserted into the table where they take tick damage
timeElapsed = tick()
}
h:TakeDamage(7)
end
end
end
end
RunService.Heartbeat:Connect(function()
checkPlayers() -- run the function
for i, v in pairs(debounce) do -- loop through the table
if tick() - v.timeElapsed >= cooldownTime then
debounce[i] = nil -- if the elapsed time is over the cooldown time, then it will remove the player from the debounce table, making them subject to taking damage
end
end
end)