Script stops working after clone rig gets deleted

i want to make a jumpscare with both the enemy and the player which i made be the rig in the jumpscare

i want it so that when the player touches enemy the jumpscare plays the problem is that it plays once and then it gives an error saying clone rig is not in workspace makes sense since i delete the clone after the jumpscare is finished and player dies but i want it so that if clone rig is deleted the script waits for him to be back like the first time

ive tried new things ive never heard of before im still a bit new with roblox studio

here is script:

local aboodirobo = workspace.Aboodirobo
local AboodiroboAnimator = aboodirobo.Humanoid.Animator

workspace.ChildAdded:Connect(function(Child)
	if Child.Name == "NewRig" then

local rig = Child
local rigHumanoid = rig.Humanoid

local PLAYER = game.Players.LocalPlayer
local CHAR = PLAYER.Character or PLAYER.CharacterAdded:Wait()
local HUMANOID = CHAR.Humanoid

local runService = game:GetService("RunService")

local PlayerDeath = game.ReplicatedStorage.playerDeath

local currentCam = workspace.CurrentCamera
local JumpscareAnim = Instance.new("Animation")
JumpscareAnim.Parent = aboodirobo
JumpscareAnim.AnimationId = "rbxassetid://17123922917"

local JumpscaredAnim = Instance.new("Animation")
JumpscaredAnim.Parent = rig
JumpscaredAnim.AnimationId = "rbxassetid://17126519378"

local JumpscareTrack = AboodiroboAnimator:LoadAnimation(JumpscareAnim)
local JumpscaredTrack = rigHumanoid:LoadAnimation(JumpscaredAnim)

local function DeathEffect()
	JumpscareTrack:Play()
	JumpscaredTrack:Play()
	
	local JumpscareEnded = false
	
	JumpscaredTrack.Stopped:Connect(function()
		JumpscareEnded = true
	end)
	
			while JumpscareEnded == false do
				game.ReplicatedStorage.Flashlight.SpotLight.Enabled = true
		currentCam.CFrame = rig.Head.CFrame
		runService.RenderStepped:Wait()
	end
end

PlayerDeath.OnClientEvent:Connect(DeathEffect)
HUMANOID.Died:Connect(function()
	script.Parent.Transparency = 0
			currentCam.CameraType = Enum.CameraType.Custom
			game.ReplicatedStorage.Flashlight.SpotLight.Enabled = false
			rig:Destroy()
			end)
		end
	end)

i put in a child added function to wait for clone rig to be added but it only does it once and then when clone rig is deleted it gives an error

try disabling the script then enabling it again after the rig is destroyed.
this may not always work but it’ll refresh the script and all of its variables including the rig variable, forgetting the one that got destroyed and making a new variable of the next rig added to workspace

script.Enabled = false
wait(0.1)
script.Enabled = true

It no longer shows an error but it still doesn’t work any other suggestions? And yes i looked to see if it disabled and re enabled and it does do that

Alright maybe try setting the rig’s parent to nil instead of destroying it?
this way the rig would still be in the game so you’re not gonna get any errors

try adding a variable and set it to true and make it that in order for the jumpscare code to run the variable mush be true and make the variable false before deleting it and when you spawn the rig back make the variable true its smt like this

local RigExist = true
function
if not RigExist then return end
do jumpscare
RigExist = false
destroy the rig


later when u add the rig again make RigExist to true

another solution is to move the rig to replicatedstorage instead of destroying it