Wait() blocking sound playing in other if statement

I have this code in a local script to play sounds when you flick a switch and I add another sound in between but with a cut off.

while true do
	wait()
	if game.workspace.Switch.Flip.Orientation.Z == 45 and played == false then
		
		played = true		
		
		game.SoundService.Switch:Play()
		
		game.SoundService.Uhoh:Play()
		wait(3)
		game.SoundService.Uhoh:Stop()
		
	end
	
	if game.workspace.Switch.Flip.Orientation.Z == -45 and played == true then
		game.SoundService.Switch:Play()
		played = false
	end
end

However, the Wait(3) in the top if statement is delaying the bottom if statement from running, How would I fix this?

You don’t need to stop the sound if it is 3 seconds long. It will stop automatically unless you looped it.

You should use coroutines. Link: coroutine | Roblox Creator Documentation

3 Likes