I'm trying to write a script that will play the first four seconds of a sound over and over after a button is clicked, then stop when another button is clicked. The script works perfectly when I'm testing the place, but whenever I go play it, the entire sound plays and it doesn't repeat. Here's the script I'm using:
v = 1 function onClicked(mouse) while v == 1 do game.Workspace.alarm:Play() wait(4) game.Workspace.alarm:Stop() end end function Click(mouse) v = 2 wait(4) v = 1 end game.Workspace.override.ClickDetector.MouseClick:connect(Click) script.Parent.ClickDetector.MouseClick:connect(onClicked)