Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Infinite Yield Possible on WaitForChild(chosenSound)?

I want to make one of the sounds play when I open the store but it doesn't work

local sound1 = script.Parent.Sound1
local sound2 = script.Parent.Sound2
local sound3 = script.Parent.Sound3 


local sounds = {
	sound1,
	sound2,
	sound3
}

local function shopMenu(otherPart)

	local player = game.Players:FindFirstChild(otherPart.Parent.Name)
	local chosenSound = sounds[math.random(1, #sounds)]

	local sound = script.Parent:WaitForChild(chosenSound) -- define your sound

	if player == LPlayer then  

		player.PlayerGui.ScreenGui.Shop.Visible = true
		
		sound:Play()
		
		player.Character.Humanoid.WalkSpeed = 0

	end
end

Close Shop Lines:

local function closeMenu()  
	if ting == 0 then
		ting = 1

	    LPlayer.PlayerGui.ScreenGui.Shop.Visible = false
	
	    script.Parent.Goodbye:Play()

	    LPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.Position.Y + 3,close.Position.Z)

		LPlayer.Character.Humanoid.WalkSpeed = 16
		wait(1) 
		ting = 0
	end
end

1 answer

"Infinite yield possible" means that the code could be waiting forever on something that isn't there.

You can add a delay argument(seconds) in line 17 for the script to wait before it gives up and stops waiting.

Example: (chosenSound, 10)

"10" means that the script will wait up to 10 seconds for the chosenSound, then after 10 seconds and it's still not there, the script stops waiting.

1 comment

0

This question was solved. Can you answer my recent question please? (If you can)

This discussion is preserved as it was. New answers, comments, and votes are closed.