Hey so im trying to code an entity for my game and it seems as if i cant get around this .Heartbeat problem. What i want it to do is fire every one second and then disconnect after 10 seconds. The reason why i cant use a while true do loop is because i want it to disconnect after 10 seconds and i dont know how to do that. Any help is appreciated.
spawn(function()
print("Spawn function")
uhdfasndhi = game:GetService("RunService").Heartbeat:Connect(function()
wait(1)
print("Damaged")
hum:TakeDamage(5)
end)
task.wait(10)
print("Disconnecting")
uhdfasndhi:Disconnect()
script.Parent:Destroy()
end)