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