Here’s a somewhat short example to get you started, it’ll require a physical part instance to represent the damaging area.
local Game = game
local Workspace = workspace
local Players = Game:GetService("Players")
local RunService = Game:GetService("RunService")
local Part = Workspace.Part --Harmful area.
local Time = 0
local function OnHeartbeat(Delta)
if Time > 10 then Time = 0 else Time += Delta return end --Frequency of 'ticks', currently once per 10 seconds.
local Models = {}
local Parts = Workspace:GetPartsInPart(Part)
for _, Part in ipairs(Parts) do
local Model = Part:FindFirstAncestorOfClass("Model")
if (not Model) or Models[Model] then continue end
Models[Model] = true
local Humanoid = Model:FindFirstChildOfClass("Humanoid")
if (not Humanoid) or Humanoid.Health <= 0 then continue end
local Player = Players:GetPlayerFromCharacter(Model)
if not Player then continue end
Humanoid:TakeDamage(10) --Damage per 'tick', currently 10.
end
end
RunService.Heartbeat:Connect(OnHeartbeat)