Problema con sistema de sonido ( script )

hello developers I hope you are well for days I have a sound error
** Which is what I want ?**
I want that when a player touches a zone a music sounds but when he touches another zone another music sounds
what is the problem ?
zone 1 has background music zone 2 has multiple music but when i play zone 1 it sounds good but if i play zone 2 the sound of zone 1 sounds but after a few seconds zone 1 sounds

zone 1 script:


local zonas = game.Workspace.zona1
local zo = game.Workspace.zonadisc
local sonido = game.StarterPlayer.StarterPlayerScripts.Sound

zonas.Touched:Connect(function()
	
		
	while sonido.SoundId ~=  "rbxassetid://11712998144"  do 
	wait(1)
		sonido.SoundId = "rbxassetid://11712998144"
		sonido:Play()
		
		zonas.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip1
		zo.Parent = game.Workspace
		while sonido.SoundId == "rbxassetid://11712998144" do
			wait(58)
			sonido.SoundId = "rbxassetid://11712998144"
			sonido:Play()
		end
		end

zone 2 script:

local zo = game.Workspace.zonadisc
local zona = game.Workspace.zona1
local sonido = game.StarterPlayer.StarterPlayerScripts.Sound

zo.Touched:Connect(function()
	if sonido.SoundId ~= "rbxassetid://11673884182" then 
	
		
	sonido.SoundId = "rbxassetid://11673884182"
	sonido:Play()
	
		while sonido.SoundId == "rbxassetid://11673884182"  do
			wait(1)
	zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
			zona.Parent = game.Workspace
			wait(189)
			
			while sonido.SoundId ==  "rbxassetid://11673884182" do
				wait(1)
				zo.Parent = game.Workspace
				
					sonido.SoundId = "rbxassetid://11673808907"
					sonido:Play()
				zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
				wait(213)
				while sonido.SoundId == "rbxassetid://11673808907" do
					wait(1)
					zo.Parent = game.Workspace
					sonido.SoundId = "rbxassetid://11666235052"
					sonido:Play()
					zo.Parent =  game.StarterPlayer.StarterPlayerScripts.zonascrip2
					wait(188)
					while sonido.SoundId ==  "rbxassetid://11666235052" do
						wait(1)
						zo.Parent = game.Workspace
						sonido.SoundId = "rbxassetid://11662744247"
						sonido:Play()
						zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
						wait(208)
						while sonido.SoundId == "rbxassetid://11662744247" do
							wait(1)
							zo.Parent = game.Workspace
							
							sonido.SoundId = "rbxassetid://11663155482"
							sonido:Play()
							zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
							wait(149)
							while sonido.SoundId == "rbxassetid://11663155482" do
								wait(1)
								zo.Parent = game.Workspace
								sonido.SoundId = "rbxassetid://11666357304"
								sonido:Play()
								zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
								wait(325)
								while sonido.SoundId == "rbxassetid://11666357304" do
								wait(1)
								zo.Parent = game.Workspace
								sonido.SoundId = "rbxassetid://11663387521"
								sonido:Play()
								zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
								wait(190)
								zo.Parent = game.Workspace
								sonido.SoundId = "rbxassetid://11673884182"
									sonido:Play()
									end
							end
						end
						
					end
				end
				
			end
		end	
	end	
	end)

if you have any questions please ask me i need your help THANKS…

It is hard to understand

  1. Rough grammar (I know you are not a native English speaker)

  2. No use of the code format button
    image

Thanks for the help, I didn’t know, I already accommodated it

Don’t do a while loop for looping, set Sound.looping to true and just play, use Sound:Stop() when the player leaves / enters another zone

thank you very much my friend thanks

Also don’t set both sound scripts to the same part


local zo = game.Workspace.zonadisc
local zona = game.Workspace.zona2
local sonido = game.StarterPlayer.StarterPlayerScripts.Sound

zo.Touched:Connect(function()
	if sonido.SoundId ~= "rbxassetid://11673884182" then 
	
		
	sonido.SoundId = "rbxassetid://11673884182"
	sonido:Play()
	
		while sonido.SoundId == "rbxassetid://11673884182"  do
			wait(1)
	zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
			zona.Parent = game.Workspace
			wait(189)
			
			while sonido.SoundId ==  "rbxassetid://11673884182" do
				wait(1)
				zo.Parent = game.Workspace
				
					sonido.SoundId = "rbxassetid://11673808907"
					sonido:Play()
				zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
				wait(213)
				while sonido.SoundId == "rbxassetid://11673808907" do
					wait(1)
					zo.Parent = game.Workspace
					sonido.SoundId = "rbxassetid://11666235052"
					sonido:Play()
					zo.Parent =  game.StarterPlayer.StarterPlayerScripts.zonascrip2
					wait(188)
					while sonido.SoundId ==  "rbxassetid://11666235052" do
						wait(1)
						zo.Parent = game.Workspace
						sonido.SoundId = "rbxassetid://11662744247"
						sonido:Play()
						zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
						wait(208)
						while sonido.SoundId == "rbxassetid://11662744247" do
							wait(1)
							zo.Parent = game.Workspace
							
							sonido.SoundId = "rbxassetid://11663155482"
							sonido:Play()
							zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
							wait(149)
							while sonido.SoundId == "rbxassetid://11663155482" do
								wait(1)
								zo.Parent = game.Workspace
								sonido.SoundId = "rbxassetid://11666357304"
								sonido:Play()
								zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
								wait(325)
								while sonido.SoundId == "rbxassetid://11666357304" do
								wait(1)
								zo.Parent = game.Workspace
								sonido.SoundId = "rbxassetid://11663387521"
								sonido:Play()
								zo.Parent = game.StarterPlayer.StarterPlayerScripts.zonascrip2
								wait(190)
								zo.Parent = game.Workspace
								sonido.SoundId = "rbxassetid://11673884182"
									sonido:Play()
									end
							end
						end
						
					end
				end
				
			end
		end	
	end	
	end)

Thank you very much if it works I will be very aware of your publications to see if I can contribute something later

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.