I have been making a script where once the play touches a part a the player plays an animation and after 7 seconds he dies and im getting this error " Workspace.Script:8: attempt to index nil with ‘WaitForChild’ - Server - Script:8"
local SS = game:GetService(“ServerStorage”)
local TeaParty = SS:WaitForChild(“TeaParty”)
local Baby = script.Parent:WaitForChild(“Baby”)
local Chair = Baby:WaitForChild(“Chair”):WaitForChild(“Base”)
Chair.Touched:Once(function(player)
local humanoid = player:FindFirstChild(“Humanoid”)
local animator = humanoid:WaitForChild(“Animator”)
local animationTrack = animator:LoadAnimation(TeaParty)
animationTrack:Play()
task.wait(7)
humanoid.Health = 0
end)
Try checking for the humanoid with an if
statement.
That’s because you’re checking if a Humanoid exists inside a Player but it doesn’t because it only exists inside the player’s character model. Try doing this:
local SS = game:GetService(“ServerStorage”)
local TeaParty = SS:WaitForChild(“TeaParty”)
local Baby = script.Parent:WaitForChild(“Baby”)
local Chair = Baby:WaitForChild(“Chair”):WaitForChild(“Base”)
Chair.Touched:Once(function(player)
local character = player.Character
if not character then return end
local humanoid = character:FindFirstChildWhichIsA("Humanoid") :: Humanoid
if not humanoid or humanoid.Health <= 0 then return end
local animator = humanoid:FindFirstChild("Animator")
local loadedAnimation = animator:LoadAnimation(TeaParty) :: AnimationTrack
if not loadedAnimation.IsPlaying then
loadedAnimation:Play()
end
task.delay(7, function()
humanoid.Health = 0
end)
end)
1 Like
now it shows an error " Character is not a valid member of MeshPart “Workspace.Hellas7777.LeftUpperLeg” - Server - Script:7"
Oops, I didn’t realized this was inside a .Touched
event.
Change this
local character = player.Character
if not character then return end
To this
local character = hit:FindFirstAncestorWhichIsA("Model")
if not character then return end
Then it should work
1 Like
it works right now Thanks a lot i appreciate you helping me out
1 Like
Move your post to Scripting Support, then mark @Free_Br1cks’s post as the solution. That, or edit the title to “[SOLVED]”
1 Like
thanks for telling me that I’m new to DevForum this helps me out
1 Like