Auto-respawning script cloning model indefinitely

Hello. I was attempting to script a auto-respawn script. When I tested it, the script was cloning the model indefinitely. and also heating up my pc hot enough to cook something on it
I don’t know what went wrong…

Script:

local model = script.Parent
local regentime = 20
regened = true

local modelclone = model:Clone()
modelclone.Parent = game.ServerStorage
model:Destroy()
local modelcloneii = modelclone:Clone()
modelcloneii.Parent = game.Workspace

while true do
	wait(regentime)
	if regened == true then
		regened = false
		local removal = game.Workspace:FindFirstChild(model.Name)
		removal:Destroy()
		local modelclone2 = modelclone:Clone()
		modelclone2.Parent = game.Workspace
		game.ReplicatedStorage.buildingregen1:FireClient()
		wait(10)
		regened = true
	end
end
2 Likes

start pc hot pocket business

As long as regened is set to true it will repeat because you have no parameters for health (is what I’m assuming) defined and being checked

Also if you want to respawn the character instantly you could set the players respawn time to 0

game.Players.RespawnTime = 0
2 Likes

i will buy pc hot pocket

If you are trying to male a model reappear whenever it disappears, then do this

workspace.DescendantRemoving:Connect(function(part)
    if part.Name == "whatever u want" then
        -- do whatever, clone it ig
    else if part.Name == "whatever else u want" then
        -- same thing
    end
end)
2 Likes

sorry for late response, i was hella busy

The script is supposed to auto-regen a model, not a player.

1 Like