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)
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)
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.
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)
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 .