Music Script Not Working

Hello everyone,

I am having trouble with a script I recently made. It is a localscript, just not sure why it isn’t working.

The Script: (game.StarterGui | localscript)

local part = game.Workspace.CafeDoor

local sounds = game.Workspace.Sounds
local db = false

local lobbymusic = true

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plrwhohit = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if plrwhohit == game.Players.LocalPlayer then
			if db == false then
				db = true

				if lobbymusic == true then
					lobbymusic = false

					for i = 0.2,0,-0.01 do
						wait()

						for i,v in pairs(sounds.Music:GetChildren()) do
							if v:IsA("Sound") then
								v.Volume = i
							end
						end
					end

					for i = 0,0.2,0.02 do
						wait()

						for i,v in pairs(sounds.CafeMusic:GetChildren()) do
							if v:IsA("Sound") then
								v.Volume = i
							end
						end
					end
				else
					lobbymusic = true

					for i = 0.2,0,-0.01 do
						wait()

						for i,v in pairs(sounds.CafeMusic:GetChildren()) do
							if v:IsA("Sound") then
								v.Volume = i
							end
						end
					end

					for i = 0,0.2,0.02 do
						wait()

						for i,v in pairs(sounds.Music:GetChildren()) do
							if v:IsA("Sound") then
								v.Volume = i
							end
						end
					end
				end

				wait(3)
				db = false
			end
		end
	end
end)

It seems that when I touch the part, the soudns inside of the “Music” folder get really loud, and the sounds in the “CafeMusic” folder get a bit louder than before. Nothing fades, and upon touching the part a second time nothing happens.

Let me know what you think!
Thanks,

I’m confused on the purpose of the loops? It’s too messy for me to figure out.

What is your goal that you are trying to achieve?

When you touch door, some sounds will fade away while others will get louder?

And you only want this heard from client i assume? I believe you need to getService for the player but im not sure, programmers will weigh in.

Also do you get any errors in output?

Also, why is script in startergui? Shouldnt it be in starterplayerscripts?

Sorry I should have explained better.

The point of the script is to fade in and out different music when a plakyer walks in and out of the cafe in my game.

Its ok, do you want the music heard only by the player and not everyone else?

I would also rewrite your i,v loop for an array this way:

With the array of songs defined at the top and then referenced in your loop ().

Why don’t you tween the volume instead of making a loop?