I'm making a death animations script and upon testing, the error
Workspace.Character.DeathAnims:4:attempt to index nil with 'WaitForChild'
appears in the output
local char = script.Parent local hum = char:WaitForChild("Humanoid") local backUpChar = char:Clone() backUpChar:WaitForChild("DeathAnims"):Destroy() hum.Died:Connect(function() local deathPos = char.HumanoidRootPart.Position local deathOri = char.HumanoidRootPart.Orientation local bac = backUpChar:Clone() local destme = char script.Parent = bac.Humanoid destme:Destroy() bac.Parent = workspace bac.HumanoidRootPart.Position = deathPos bac.HumanoidRootPart.Orientation = deathOri bac:MakeJoints() hum = bac.Humanoid hum.HealthDisplayDistance = 0 hum.MaxHealth = math.huge hum.Health = math.huge local death_Anim = Instance.new("Animation") death_Anim.AnimationId = 'rbxassetid://4643698669' local track = hum:LoadAnimation(death_Anim) --script.Parent.Parent.HumanoidRootPart.Anchored = true track.Priority = Enum.AnimationPriority.Action track:Play() wait(0.66) hum.Health = 0 script:Destroy() end)
Ooh this is good example of Roblox properties messing with people.
Characters automatically come with their Archivable
property off, which means it cannot be cloned without turning the property back on first. All you need to do to fix up your script is: before your WaitForChild
line which errors, set char.Archivable
to true.
If you wanna know more about the property there is more on the dev wiki here.
I recommend using Find First Child
backUpChar:FindFirstChild("DeathAnims"):Destroy()
I have had this same type of problem, I did some research and found out that "WaitForChild()" has a "TimeOut" feature meaning you can set how long you want is to wait for:
the "10" represents however long you want it
WaitForChild("Name To Search For", 10)