Music Settings script help!

local player = game.Players.LocalPlayer
local trigger = true -- On {0.25, 0},{0.5, 0} c =34, 255, 0
local destroy = coroutine.create(function()
	while trigger == true do
		wait()
		game.Workspace:FindFirstChild("CurrentSong").Volume = 0
	end
end)

script.Parent.MouseButton1Click:Connect(function()
	if trigger == true then
		print("Music Disabled")
		coroutine.resume(destroy)
		if game.Workspace:FindFirstChild("CurrentSong") == nil then
			for i, v in pairs(game.Workspace.MainFrame.Songs:GetChildren()) do
				v.Volume = 0
			end
		else
			game.Workspace.CurrentSong.Volume = 0
		end
		script.Parent.Parent.Move:TweenPosition(UDim2.new(0.75, 0, 0.5, 0), "Out", "Quart", 0.3)
		script.Parent.Parent.Move.ImageColor3 = Color3.fromRGB(255, 78, 81)
		trigger = false
	else
		print("Music Enabled")
		if game.Workspace:FindFirstChild("CurrentSong") == nil then
			for i, v in pairs(game.Workspace.MainFrame.Songs:GetChildren()) do
				v.Volume = 0.5
			end
		else
			game.Workspace.CurrentSong.Volume = 0.5
		end
		script.Parent.Parent.Move:TweenPosition(UDim2.new(0.25, 0, 0.5, 0), "Out", "Quart", 0.3)
		script.Parent.Parent.Move.ImageColor3 = Color3.fromRGB(34, 255, 0)
		trigger = true
	end
end)

This is my current script for the settings menu and for some reason it worked but has stopped working, I get an error saying [attempt to index nil with ā€˜Volume’] on line 6 but not sure how to fix this. Btw I’ve only recently started scripting. Any fixes are appreciated!

2 Likes

Is this a local script or a sever script?

Local script, it used to be a script before. But i only wanted it to change for that one player.

Is ā€œCurrentSongā€ a sound? image

Yeah, It is created when the game starts and parented to workspace

Hmm. Well I think the sound isn’t created in time so your script can’t find the sound. Try manually putting a Sound in the workplace and see if it works.

Yeah that works. (30 charssss)

1 Like

Should i do

game.Workspace.WaitForChild("CurrentSong").Volume = 0

Yeah WaitForChild would also work. Because you are waiting for it to load.

Thanks for the help! :heart:

(30)

1 Like