so, i was doing scripts for a zombie, i wanted to do a script that will chase the nearest player and will damage them with 10 health (i did that script with AI)
here is my script
local zombie = script.Parent
local humanoid = zombie:FindFirstChildOfClass("Humanoid")
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
-- Damage settings
local DAMAGE_AMOUNT = 10
local DEBOUNCE_TIME = 1 -- seconds
-- Debounce table to prevent rapid damage
local touchDebounce = {}
-- Helper function to apply damage
local function applyDamageToPlayer(hit)
local character = hit.Parent
if character and Players:GetPlayerFromCharacter(character) then
local playerHumanoid = character:FindFirstChildOfClass("Humanoid")
if playerHumanoid and playerHumanoid.Health > 0 then
local playerId = character:GetDebugId()
if not touchDebounce[playerId] then
playerHumanoid.Health = playerHumanoid.Health - DAMAGE_AMOUNT
touchDebounce[playerId] = true
task.delay(DEBOUNCE_TIME, function()
touchDebounce[playerId] = nil
end)
end
end
end
end
second part in the comments