I'm trying to make for my door script, where when you come close to the door a sound plays, and a GUI pops up. I got everything working, however I cannot get this to work.
I’ve noticed the issue is mainly that its probably playing then stopping immediately
I haven’t tried much solutions except adding a debounce or some other things.
Here is the local script, (I only want the sound to play for the client, that’s the reason.):
local mag2 = (Character.HumanoidRootPart.Position - Door.Center.Position).magnitude if mag2 <= Door.Config.Range.Value then if not played then sound:Play() wait(0.1) played = true if played == true then sound:Stop() played = false end end end
The if
statement is fired immediately after played
is set to true
, in conclusion, your hypothesis is slightly correct, the soundtrack is stopped how it was supposed to be in respect to the program, however, it's stopped too quickly, that is your issue. If you wish to have the soundtrack stopped when it's complete, try using the isPlaying
signal instead, or you can simply just call Play
and let it stop on it's own:
local Sound = workspace.Sound -- Conditionals for playing the sound. sound:Play() if not (Sound.isPlaying) then sound.Stop() end
If you're wanting to cut the soundtrack quickly, to play a certain piece of the track, it may be better to try adjusting the yielding value.
Just another tip
This may also be a cause of your problem. A Sound
instance is required to be placed within the workspace
to functionally operate; if the instance is elsewhere, it won't play.
If this is the cause, adjusting the location will not affect your desire to play it locally.