Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

WaitForChild not working?

Asked by 9 years ago

Okay, so pretty much...I have 2 scripts...

local girl = game.Workspace.Girl1
local Sound = script.Sound:WaitForChild()
script.Parent.Touched:connect(function()
    Sound:Play()
    girl.Arm2.Transparency = 0
    girl.Arm1.Transparency = 0
    girl.Head.Transparency = 0
    girl.Dress.Transparency = 0
    girl.Shoe1.Transparency = 0
    girl.Shoe2.Transparency = 0
    girl.Leg1.Transparency = 0
    girl.Leg2.Transparency = 0
    girl.Hair.Transparency = 0
    girl.Head.Decal.Transparency = 0
    wait(5)
    girl.Arm2.Transparency = 1
    girl.Arm1.Transparency = 1
    girl.Head.Transparency = 1
    girl.Dress.Transparency = 1
    girl.Shoe1.Transparency = 1
    girl.Shoe2.Transparency = 1
    girl.Leg1.Transparency = 1
    girl.Leg2.Transparency = 1
    girl.Hair.Transparency = 1
    girl.Head.Decal.Transparency = 1
    print("Jumpscare1 Part 1 of 2 success!")
script.Disabled = true
end)

and

local image = game.StarterGui.Jumpscare1.Image:WaitForChild()
local Sound2 = script.Sound2:WaitForChild()
local Sound3 = script.Sound3:WaitForChild()
local Sound4 = script.Sound4:WaitForChild()
script.Parent.Touched:connect(function()
wait(2)
    image.Visible = true
    script.Sound2:Play()
    wait(3)
    image.Visible = false
    Sound2:Stop()
    Sound3:Play()
    Sound4:Play()
    wait(10)
    Sound3:Stop()
    Sound4:Stop()
print("Jumpscare1 Part 2 of 2 success!")
script.Disabled = true
end)


Its for my halloween project, and for some reason WaitForChild never seems to pick up that the objects are there, so then it just waits for ever. The only error i'm getting in the output is "Argument 1 missing or nil" but its not missing OR nil...I'm really confused. I think you can tell what the scripts doing, but pretty much, a girl pops up behind the player, it plays a sound, then a few seconds pass and its gone again. That script is then disabled to prevent repeats... Then the second one triggers a jumpscare, sound, and then breathing and heartbeat noises. It is disabled as well.

1 answer

Log in to vote
1
Answered by 9 years ago

Well first off, this part won't work,

local Sound = script.Sound:WaitForChild()

Because you are looking for something in script.Sound I think you are wanting it to wait for the sound, so that would be,

local girl = game.Workspace.Girl1
local Sound = script:WaitForChild("Sound")
script.Parent.Touched:connect(function()
    Sound:Play()
    girl.Arm2.Transparency = 0
    girl.Arm1.Transparency = 0
    girl.Head.Transparency = 0
    girl.Dress.Transparency = 0
    girl.Shoe1.Transparency = 0
    girl.Shoe2.Transparency = 0
    girl.Leg1.Transparency = 0
    girl.Leg2.Transparency = 0
    girl.Hair.Transparency = 0
    girl.Head.Decal.Transparency = 0
    wait(5)
    girl.Arm2.Transparency = 1
    girl.Arm1.Transparency = 1
    girl.Head.Transparency = 1
    girl.Dress.Transparency = 1
    girl.Shoe1.Transparency = 1
    girl.Shoe2.Transparency = 1
    girl.Leg1.Transparency = 1
    girl.Leg2.Transparency = 1
    girl.Hair.Transparency = 1
    girl.Head.Decal.Transparency = 1
    print("Jumpscare1 Part 1 of 2 success!")
script.Disabled = true
end)

If this helps, please accept my answer, it gives us both rep!

0
It fixed the first problem...the output printed it and everything, but the GUI never popped up like it was supposed to...Any idea why that part didn't work? clalexander 40 — 9y
0
local image = game.StarterGui.Jumpscare1.Image:WaitForChild() local Sound2 = script.Sound2:WaitForChild() local Sound3 = script.Sound3:WaitForChild() local Sound4 = script.Sound4:WaitForChild() yet again, wrong way round for the :WaitForChild(""), could you accept my answer, please? ScriptFusion 210 — 9y
Ad

Answer this question