Help With Sound Effect GUI

Hi, I Am Working On A Sound Effect GUI For My Game. In My Game There Is Background Music That Just Keeps Looping. I Have Text Buttons With Local Scripts Inside (See Script Below)

script.Parent.MouseButton1Click:Connect(function()
	game.Workspace.Powerup.Playing = false
	game.Workspace.Gold.Playing = true
	wait(3)
	game.Workspace.Gold.Playing = false
	game.Workspace.Powerup.Playing = true
end)

Currently The Sound Only Changes For The Person Who Clicked The Button But I Want It To Play For Everyone Since Only Admins Have Access To This GUI.

I Also Was Wondering If There Was A Better Way To Write This Script As If You Spam The Buttons, All The Sounds Stop Playing.

Thanks!

1 Like

Is the script that is changing it a LocalScript or a ServerScript?

EDIT: I am an idiot. You need to use a ServerScript for it to work ServerSided

If you want a delay use a debouce.

local db = true -- Debounce

local waitTime = 2

script.Parent.MouseButton1Click:Connect(function()
	if db then
		db = false
		game.Workspace.Powerup.Playing = false
		game.Workspace.Gold.Playing = true
		wait(3)
		game.Workspace.Gold.Playing = false
		game.Workspace.Powerup.Playing = true
		wait(waitTime)
		db = true
	end
end)

So I Should Put This In A Local Script In The Button?

No. Make it a ServerScript because LocalScripts only effect the client that clicked the button.

So I Put That Script In A Normal Script In Server Script Service?

Do I Need To Put A Script Inside The Button?

I Have Seven Buttons Playing Different Sound Effects
Should I Put A Script In Server Script Service For Every Button?

I think you misread my point. Change that Local Script to a Server Script NOTHING else

1 Like

Ok So I Should Make The Local Script That Is In The Button A Normal Script And Then Put That Code In The Script?

Correct! Thats exactly what you should do.

Ok
I’m Gonna Try It Now
Thanks!

local canClick = true

local cooldown = 1 -- insert your ideal cooldown

script.Parent.MouseButton1Click:Connect(function()
	if canClick then
		canClick = false
		game.Workspace.Powerup.Playing = false
		game.Workspace.Gold.Playing = true
		task.wait(3) -- use task.wait it is bettter than wait
		game.Workspace.Gold.Playing = false
		game.Workspace.Powerup.Playing = true
		task.wait(cooldown)-- use task.wait it is bettter than wait
		canClick = true
	end
end)

Anything that task contains is usally better than the original, whether its a wait or a spawn, the task version is much more efficient.

No problamo. Glad I could help

You can’t use
script.Parent.MouseButton1Click:Connect(function()
in the server so you need to use a remote event to fire from the client to the server.

local canClick = true
local REP = game:GetService("ReplicatedStorage")
local remote = REP.remote -- put your remote here
local cooldown = 1
script.Parent.MouseButton1Click:Connect(function()
	remote:FireServer(canClick, cooldown) -- you could do the cooldown serversided
-- but here I pass the values to the server so I can do the cooldown and check canClick there
end)

See now that is where you are wrong.

putting

script.Parent.MouseButton1Click:Connect(function()
	
	print("eerfsfg")
	
end)

inside a text button and the script being ServerScript it works perfectly fine.

I guess you could do it that way, lol for some reason I actually never did something like that before, I went into math OOP and all that stuff but never knew that you could put a script into a button, that’s quite unfortunate :joy: .

Well, you learn something new everyday.

1 Like

Oh and trust me I can relate similar to that untill i’m proven wrong or I look it up to correct myself.

Either way, He supports your effort into helping him.

1 Like

Thank you very much, I wish you all the best my friend :+1:

Same with you. Have a great rest of your day or night

1 Like