I have a respawn script I want to cap it so the npc respawns only 5 time when killed can someone please look at it and help me
local RespawnTime = 5
while true do
character = script.Parent
clone = character:Clone()
character.Humanoid.Died:wait()
wait(RespawnTime)
clone.Parent = script.Parent.Parent
script.Parent = clone
character:Destroy()
end
if the respawntime is larger than zero, it will subtract 1 from respawntime
didnt u already made a function that has the value of 5? dont have to cap it
local RespawnTime = 5
while true do
character = script.Parent
clone = character:Clone()
character.Humanoid.Died:wait()
wait(RespawnTime)
if RespawnTime > 0 then
RespawnTime = RespawnTime - 1
clone.Parent = script.Parent.Parent
script.Parent = clone
character:Destroy()
end
end
Try putting your while true code inside a for loop.
local RespawnTime = 5
for i = 1, 5 do
character = script.Parent
clone = character:Clone()
character.Humanoid.Died:wait()
wait(RespawnTime)
clone.Parent = script.Parent.Parent
script.Parent = clone
character:Destroy()
end
Or you can use a variable that’s a number and increases each time the the character dies, if it’s 5 or above then you’ll break the loop.