I Have a ObjectValue inside my script that Stores the Sound object the i want to play
im trying to make a debounce so when the player clicks the first time it plays
and when the player clicks the second time it stops
now the problem is it dosent work
script.Parent.MouseButton1Click:Connect(function()
local isplaying = false
if isplaying == false then
isplaying = true
script.Parent.Play_Sound.Value:Play()
else
if isplaying == true then
isplaying = false
script.Parent.Play_Sound.Value:Stop()
end
end
end)
“now the problem is it dosent work” is a very vague statement. Remember, we can’t read your mind.
Does the sound not play ever?
Does the sound play and not shut off?
You change the value of isplaying every time the function is called, so it always does the if isplaying == false section of the script.
Do you get errors in the Output Window when testing?
Is the Sound parented inside the same Part the script is in?
How does the other script reference the Play_Sound.Value
Why not just Play the sound, instead of changing a value required by another script?
local isplaying = false
script.Parent.MouseButton1Click:Connect(function()
if isplaying == false then
isplaying = true
script.Parent.**soundname**:Play()
else
if isplaying == true then
isplaying = false
script.Parent.**soundname**:Stop()
end
end
end)
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Play_Sound.Value.IsPlaying then
script.Parent.Play_Sound.Value:Stop()
else
script.Parent.Play_Sound.Value:Play()
else
end)
Waiting = false
WaitTime = 2 -- Change this to however you like.
Button.Activated:Connect(function() -- This is so it can be Activated on all Devices (idk thats what people tell me)
if not Waiting then -- Not sure why this works but it does, im stupid
Waiting = true -- Delay Starts
Sound:Play() -- Da Sown Plaes
task.wait(WaitTime) -- Delay Time
Waiting = false -- Delay Ends
end
end)
If you want to add a wait until the sound is finished (Looking at it again, doesnt appear to be the case), follow the post above mine.