Hello I couldn’t get a good name for the title sorry
I was wondering where do I put a wait event in my script so the sound doesnt spam when you click on the gui.
what i mean is when you click the gui it plays the sound then when the sound is finished and your still clicking then it will play it again rather than just playing the first millisecond on a click
this is the script:
function PlaySound(play)
local sound = script.Parent.ClickSound -- Sound Name
sound:Play()
end
script.Parent.MouseButton1Click:Connect(PlaySound)
I’m kind of new to scripting so thanks if anyone can help out.
You can check if it’s playing or not using .IsPlaying, like such
function PlaySound(play)
local sound = script.Parent.ClickSound -- Sound Name
if not sound.IsPlaying then
sound:Play()
end
end
script.Parent.MouseButton1Click:Connect(PlaySound)
local db = false
function PlaySound(play)
local sound = script.Parent.ClickSound -- Sound Name
if not db then
db = true
sound:Play()
task.wait(1)
db = false
end
end
script.Parent.MouseButton1Click:Connect(PlaySound)
^ You wont be able to play the sound until one second has passed, if you want the sound to be able to be played again only once it’s done, try using a .Ended function to detect if the song has ended.^
local db = false
function PlaySound(play)
local sound = script.Parent.ClickSound -- Sound Name
if not db then
db = true
sound:Play()
sound.Ended:Wait()
db = false
end
end
script.Parent.MouseButton1Click:Connect(PlaySound)