I wanted to make a JumpScare animation that plays in the exact place the player dies
I’m not good at explaining but I’ll try, when the enemy ai touches the player the jumpscare is supposed to play like this:
but I always get the warning: infinite possible Yields on workspace:waitforchild(NewRig)
and the jumpscare only plays correctly once
I know the reason it says that is because it isn’t able to find the rig clone and the reason is because the rig wasn’t cloned yet it waits for the jumpscare to happen so it can get cloned how can I make it so that it waits for rig to be cloned and put into workspace before the script runs
Here is script:
local aboodirobo = workspace.Aboodirobo
local AboodiroboAnimator = aboodirobo.Humanoid.Animator
local rig = workspace:WaitForChild("NewRig")
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
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
end)
A very simple way you could do this is to put your client code inside the jumpscare rig:
Add a Script to the jumpscare rig
Set the Script’s .RunContext to client (so it runs on the client like a LocalScript)
Paste your code in the Script
Change local rig = ... to local rig = script.Parent
This would mean that your client code would run the moment the jumpscare rig is replicated.
If you need to wait for the NewRig to be added, you could use the Workspace.ChildAdded event and check if the new child is the rig (and if it is then run your code).
(Also remember to check the existing children of Workspace in addition to the ones from ChildAdded.)
so I ignored the first part but I did the Workspace.ChildAdded part and it no longer gives me the warning but it still only works once then shows an error and that is because I delete the Clone after the jumpscare is done. here is the new code so you can see the changes if you want
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
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
rig:Destroy()
end)
end
end)