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

Did i write this code correctly? I'm trying to make a gun suppression system.

Asked by 10 years ago

So, i am trying to make a suppression system for the guns. (When you get shot at you hear sounds around bullet impact sounds around you) this is a script i put together, it doesn't seem to be working and in the console something seems to be wrong with line 7. (Or so it said) Here's the code:

models = game.Workspace:GetChildren()
stringToFind = "Ignore_Model"

for _,v in pairs(models) do
 model = string.match(v.Name, stringToFind)
 if model:IsA("Model") and model then
  print('Found: '..v.Name)
  subModel = model:FindFirstChild('Gun_Ignore')
  if subModel then
   subModelChilds = subModel:GetChildren()
   for _,v in pairs(subModelChilds) do
    if v.Name == "Bullet" and v:IsA("Part") then
     local sound = Instance.new("Sound", v)
     sound.SoundId = "http://www.roblox.com/asset/?id=190321873"
     sound:Play()
    end
   end
  end
 end
end

Basically I'm trying to find a model that is created named "Ignore_Model_(Random numbers)" The model has 2 words that are always the same "Ignore_Model" but then it randomly generates numbers, inside "Ignore_Model_" there is a group called "Gun_Ignore" Everytime the gun is fired, a child named "Bullet" (A part) is created, i'm trying to create a sound instance inside of this part, this script doesn't seem to be working.

If you could help that would be great, thank you!

Answer this question