Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Audio cutting off for automatic gun?

Asked by 5 years ago

So I'm scripting an automatic gun and I have a repeat loop used for firing bullets. Every time this loops, I play the gunfire sound. The problem is that when the sound loops, the new gunshot cuts off the old gunshot (just like replaying the audio file). I'm wondering how to make it so that it doesn't replay the audio and instead the gunshots don't affect one another. I thought of making 2 sound Instances and interchanging them and it works but I'm not sure that is the best way to go about this.

local sound = tool:WaitForChild("Gunfire")
repeat
    sound:Play()
    ...
    ...
until shooting == false 

What should I do?

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I had the same problem a while back, I figured out for me it was just the audio. You need to make sure its just the right time, not too long, but not too short. I'm pretty sure its your audio not your script. Hopefully this helps!????-Mrmonkeyman120

0
I don't think its the audio, I think its that playing an audio while its already playing replays it instead of playing both of them. I was just hoping to see if there was an easy way to do that Ido_nothaveUsername 213 — 5y
0
Hmm, Let me try to figure something out.. Mrmonkeyman120 65 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Well you can try going to the sound in the explorer, and checking the length, then cutting it off where you desire like so

(say the sound is somehow exactly 2 seconds long but to make it sound better I want it to stop at 1.2)

local sound = tool:WaitForChild("Gunfire")
repeat
sound:Play()
wait(1.2)
sound.Playing = false -- this could be == false instead
...
...

until shooting == false
0
I want multiple gunshots playing at the same time because the rate of fire is high, so doing this affect the quality of the sound or make the rate of fire slower(same as the duration of the audio) Ido_nothaveUsername 213 — 5y
0
ok, i'll think of something. right now, i'm working on something so i'll try and help later. Just_Moop 27 — 5y
Log in to vote
0
Answered by 5 years ago

NVM, I found that I could just create a new sound instance every time in the loop, play it and destroy it.

Answer this question