script:WaitForChild("MainMenuMusic"):Play()

script.Parent.MouseButton1Click:connect(function()
	local StarterGui = game:GetService("StarterGui")
	local MainMenuGui = StarterGui:WaitForChild("MainMenuGui")
	local MainMenu = MainMenuGui:WaitForChild("MainMenu")
	local FadeIn = MainMenu:WaitForChild("Fadein")
	local Sound = script:WaitForChild("MainMenuMusic")
	local Sound2 = script:WaitForChild("StarterVillageMusic")
	
	for i =1,50 do
		wait(0.1)
		Sound.Volume = Sound.Volume - 0.03
		FadeIn.BackgroundTransparency = FadeIn.BackgroundTransparency - 0.07
	end
	Sound:Stop()
	Sound2:Play()
	MainMenu.Visible = false
	
	for i = 1,50 do
		wait(0.1)
		FadeIn.BackgroundTransparency = FadeIn.BackgroundTransparency + 0.07
	end
end)

I'm having trouble on making this work. Can someone teach me how to use WaitForChild("") correctly?

3 comments

1

You seem to be using it correctly in your code but you are accessing the StarterGui and not the players gui.

1

If the child with the name is not found a warning will be displayed in the output saying about an infinate yield.

0

Oh, thanks!