Hello!! i want to make my custom zombie NPC from scratch be able to damage players health little by little, Its already following the player its just that little detail that i want to add, I have tried chatgpt and youtube but surprisingly they didnt really help with something good. Please add a simple damage system to this existing script inside my dummy/zombie:
//////////////////////
local npc = script.Parent
local humanoid = npc:WaitForChild(“Humanoid”)
local runService = game:GetService(“RunService”)
npc.Humanoid.WalkSpeed = 10 – Adjust the speed here
runService.Heartbeat:Connect(function()
local nearestPlayer, shortestDistance
for _, player in pairs(game.Players:GetPlayers()) do
local character = player.Character
if character and character:FindFirstChild(“HumanoidRootPart”) then
local distance = (character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
if not shortestDistance or distance < shortestDistance then
nearestPlayer = character
shortestDistance = distance
end
end
end
if nearestPlayer then
humanoid:MoveTo(nearestPlayer.HumanoidRootPart.Position)
end
end)