Mouse Click sound script Not Working

Hi!
Really nothing else is needed. I recycled an old Theme script, so it’s pretty messy. I hear the clicks at the start, but nothing happens when I click the buttons.
Thanks!

local a = 0
local b = 0
local ended = false
local SOUND = script.Sound
function RemoveTableDupes(tab)
	local hash = {}
	local res = {}
	for _,v in ipairs(tab) do
		if (not hash[v]) then
			res[#res+1] = v
			hash[v] = true
		end
	end
	return res
end






task.wait(15)

local OBJECTS = {}

for i, obj in pairs(game.Players.LocalPlayer:WaitForChild("PlayerGui"):GetDescendants()) do
	if obj:IsA("GuiObject") and obj.Parent ~= script.Parent and obj.Parent.Parent ~= script.Parent then
		--Found a GuiObject
		if obj:IsA("ImageButton") then
			a += 1
			table.insert(OBJECTS, obj)
		end

	elseif obj:IsA("TextButton") then
		a+=1
		table.insert(OBJECTS, obj)

	end
end

OBJECTS = RemoveTableDupes(OBJECTS)

function OpenLoading()
	local frame = game.Players.LocalPlayer.PlayerGui.ChangeSetting.Frame
	frame.Visible = true
	frame.lab.Text = "Initalizing..."
	task.wait(2)
end
function CloseLoading()
	local frame = game.Players.LocalPlayer.PlayerGui.ChangeSetting.Frame
	frame.Visible = false
end
local function SetAllColors(color)
	for i, obj in pairs(OBJECTS) do
		if obj:IsA("GuiObject") and obj.Parent ~= script.Parent and obj.Parent.Parent ~= script.Parent then
			--Found a GuiObject
			task.wait()
			if obj:IsA("ImageButton") or obj:IsA("ImageLabel") then
				b += 1
				local e = Instance.new("Sound")
				e.SoundId = "rbxassetid://178104975"
				e.Volume = 2
				e.Parent = obj
				e:Play()
				obj.MouseButton1Click:Connect(function()
					e:Play()
				end)
			end
		elseif obj:IsA("TextButton") then
			b += 1
			local e = Instance.new("Sound")
			e.SoundId = "rbxassetid://178104975"
			e.Volume = 2
			e.Parent = obj
			e:Play()
			obj.MouseButton1Click:Connect(function()
				e:Play()
			end)
		end
	end
end

game.Players.LocalPlayer.PlayerGui.ChangeSetting.Frame.lab.Text = "Loading.. ["..b.."/"..a.."]"
ended = true

SetAllColors(game.Players.LocalPlayer:WaitForChild("Theme").Value)

1 Like

Any errors displayed in console?

1 Like

No

1 Like

you don’t have to do 10000 lines to play a sound. Do this instead:

local Button = script.Parent
Button.MouseButton1Click:Connect(function()
	local e = Instance.new("Sound")
	e.SoundId = "rbxassetid://178104975"
	e.Volume = 2
	e.Parent = game.SoundService
	e:Play()
end)
1 Like

i know how that would happen, i dont want to go into every single button to add the script, it creates the script for every button.

1 Like

I would recommend doing so but suit your bubble.

1 Like

That’s one alternative way of doing something easy.

2 Likes

I’m not sure what the problem is. However, I have faced a somewhat similar problem.

Instead of making the sound play, you could set the Playing property to true.

Please let me know the results.

1 Like
local sound = script.Parent:WaitForChild("Sound")
local button = script.Parent

button.MouseButton1Click:Connect(function()
	sound:Play()
end)

Even simpler way.

1 Like

I think the parent of the sound should be set to a part or a model?
try setting the parent of sound to the character model maybe

1 Like

So, now I have this.

local a = 0
local b = 0
local ended = false
local SOUND = script.Sound
function RemoveTableDupes(tab)
	local hash = {}
	local res = {}
	for _,v in ipairs(tab) do
		if (not hash[v]) then
			res[#res+1] = v
			hash[v] = true
		end
	end
	return res
end

task.wait(15)

local OBJECTS = {}

for i, obj in pairs(game.Players.LocalPlayer:WaitForChild("PlayerGui"):GetDescendants()) do
	if obj:IsA("GuiObject") and obj.Parent ~= script.Parent and obj.Parent.Parent ~= script.Parent then
		--Found a GuiObject
		if obj:IsA("ImageButton") then
			a += 1
			table.insert(OBJECTS, obj)
		end

	elseif obj:IsA("TextButton") then
		a+=1
		table.insert(OBJECTS, obj)

	end
end

OBJECTS = RemoveTableDupes(OBJECTS)

function OpenLoading()
	local frame = game.Players.LocalPlayer.PlayerGui.ChangeSetting.Frame
	frame.Visible = true
	frame.lab.Text = "Initalizing..."
	task.wait(2)
end
function CloseLoading()
	local frame = game.Players.LocalPlayer.PlayerGui.ChangeSetting.Frame
	frame.Visible = false
end
local function SetAllColors(color)
	for i, obj in pairs(OBJECTS) do
		if obj:IsA("GuiObject") and obj.Parent ~= script.Parent and obj.Parent.Parent ~= script.Parent then
			--Found a GuiObject
			task.wait()
			if obj:IsA("ImageButton") then
				b += 1
				local e = Instance.new("Sound")
				e.SoundId = "rbxassetid://178104975"
				e.Volume = 2
				e.Parent = script
				e:Play()
				local scr = script.LocalScript:Clone()
				scr.Parent = obj.Parent
				scr.Disabled = false
				e:Destroy()
			end
		elseif obj:IsA("TextButton") then
			b += 1
			local e = Instance.new("Sound")
			e.SoundId = "rbxassetid://178104975"
			e.Volume = 2
			e.Parent = obj
			e:Play()
			local scr = script.LocalScript:Clone()
			scr.Parent = obj.Parent
			scr.Disabled = false
			e:Destroy()
		end
	end
end

game.Players.LocalPlayer.PlayerGui.ChangeSetting.Frame.lab.Text = "Loading.. ["..b.."/"..a.."]"
ended = true

SetAllColors(game.Players.LocalPlayer:WaitForChild("Theme").Value)

In the other script:

local SoundClick = Instance.new("Sound",script.Parent)
SoundClick.SoundId = "rbxassetid://178104975"
local SoundEnter = Instance.new("Sound",script.Parent)
SoundEnter.SoundId = "rbxassetid://1412830375"
SoundEnter.Volume = 2
SoundClick.Volume = 2
script.Parent.MouseButton1Click:Connect(function()
	SoundClick:Play()
end)

script.Parent.MouseEnter:Connect(function()
	SoundEnter:Play()
end)
script.Parent.MouseLeave:Connect(function()
	SoundEnter:Play()
end)

And this happens.

I don’t have the time to go through the whole script but I understand that you want to have one script do the work for all of the buttons and play the sound when you click them?

local plr = game.Players.LocalPlayer
local sound = script.Sound -- the reason I did this is just so it's easier for you to understand but if you have a other place where you store sounds set the path to that, but you can put the sound inside the script

-- looping throught the buttons --

for i, button in pairs(buttonsHolder:GetChildren()) do
   button.MouseButton1Click:Connect(function()
      sound:Play()
   end
end

Also I think you create a multiple sounds? There’s no need for that, you can just use one.