I’m trying to make a door that makes a sound when it opens. But when I activated the sound it keeps repeating as long as I’m touching the scripted block. Is there any way I can add a delay in between the sounds?
Please show the script instead. I highly doubt someone is willing to download.
sorry i didnt know how to upload the video
this is the script, what do I need to do?
For one, you didn’t get the Sound Service. Second, you never defined the Id of the Sound.
Personally, I’d use an “if” statement to remove extra sounds added. For this situation, I’d create a new variable (local canPlay = true
), and if the player has touched once, it’ll check if canPlay is set to true. When it’s set to true, you’d then set it to false, and once the sound has stopped playing, you can set it back to true.
local canPlay = true
local part = script.Parent
D1 = part.Parent.Door
D2 = part.Parent.Door2
function onTouched() -- we don't need "part" in the parameter as you're not identifying anything
if canPlay then
canPlay = false
D1.CanCollide = false
D1.Transparency = 1
script.Parent.Sound:Play()
D2.CanCollide = true
D2.Transparency = 0
wait(1)
part.Sound1:Play()
D1.CanCollide = true
D1.Transparency = 1
D2.CanCollide = true
part.Sound1.Ended:Wait()
canPlay = true
end
part.Touched:Connect(onTouched)
I tried that, but it but it seemed to break the door
How would you write it with sound service?
Local SoundService = game:GetServive("SoundService")
How did it break the door? Is the collision not working or the sound?
I Actually tried to add the sound effects to a separate Part and it worked perfect