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

Firing sound ?

Asked by
Bulvyte 388 Moderation Voter
7 years ago
Edited 7 years ago
function Fire_Gun()
    local FireSound = Handle:FindFirstChild("FireSound")
    local Bullet = Handle:FindFirstChild("Bullet")

    if FireSound then FireSound:Play() end
    wait(0.2) -- if i add a wait here it won't work, because the gun can fire only every 0.2 seconds so no
    if Bullet then Bullet:Play() end

So the prob i got is, the sound when gun's fired it plays FireSound and bullet, but if the gun fires like 1000 bullets per minute it's very hard to hear or u just don't hear it. Also the bullet sound sometimes plays first rather than firesound

Fire sound always needs to be first and bullet sounds play like 0.2 seconds later but it fails, how can i make it hear when the weapon fires very fast ?

Also, is there a way to run the whole script but make 1 line wait ? Hope you understand what i mean :)

Please, don't change the script it's fine just explain what's wrong :D

1 answer

Log in to vote
1
Answered by
deris88 146
7 years ago
Edited 7 years ago

Well sound length is a lot more than .2 seconds. Only solution here is adjust time position in sound or increase the pitch. Or you can do this:

-- every time you shoot create a new sound:
if FireSound then
  local ss = Instance.new('Sound') --shoot sound
  ss.SoundId = 'SoundID'
  ss.Volume = 1
  ss.Pitch = 1
  ss:Play()
  ss.Parent = script.Parent
  wait(length of sound)
  ss:remove()
end

You need experiment with that! However gun probably will shoot every ' wait(length of sound)'.

In that case you can create another script. Remove the ss:remove() from script above.

while wait(5) do
 local sounds = script.Parent:GetChildren()
 for i= 1,#sounds do
if sounds[i].ClassName  == '(check the sound class name, i forgot :D)' then
sounds[i]:remove()
end
end
end

This will solve the case!

0
What do u mean check the sound class name, i forgot ?... Bulvyte 388 — 7y
0
Nvm, u type 1 equal when u needed 2 == Bulvyte 388 — 7y
0
Wel you see every part,instance has ClassName for example block's class name is 'Part', wedges -'Wedge', for script-'Script' deris88 146 — 7y
0
Yes I forgot == :D deris88 146 — 7y
0
Tell me if that works for you! deris88 146 — 7y
Ad

Answer this question