I’m a new dev and can’t tell if my heartbeat function is being overworked
This script uses the heartbeat function to tell if a npc or player has died and then respawns them.
local function handleCharacter(character: any)
if character:IsA("Model") and character:FindFirstChild("Humanoid") then
local IsEnemy = character:GetAttribute("IsEnemy")
local player = Players:GetPlayerFromCharacter(character)
local botClone = nil
local Humanoid = character:WaitForChild("Humanoid")
local rootPart = character:FindFirstChild("HumanoidRootPart")
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
local isdead = false
local npcClone = character:Clone()
character:SetAttribute("Ragdolled", false)
character:SetAttribute("Aerial", false)
local function deathcheck()
if isdead then
return
end
if Humanoid.Health > 0 and rootPart.Position.Y >= -500 then
isdead = false
return
else
isdead = true
coroutine.wrap(RagdollService.RagdollCharacter)(character, 2000, true)
print("died")
task.wait(5)
print("respawned")
if player then
respawnCharacter(player)
else
character:Destroy()
npcClone.Parent = Workspace.Characters
handleCharacter(npcClone)
end
end
end
RunService.Heartbeat:Connect(function()
deathcheck()
end)
end
end