Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

im having trouble finding a way to add sound to my weapon?

this gun shoot silent, i want to add sound to it when it shoots, how would i do that?

player = game.Players.LocalPlayer
mouse = player:GetMouse()
damage = 10
reload = 1.5
rate = 0.1
name = script.Parent.Name
fire = true
Type = "Auto"
MaxClip = 30
Clip = MaxClip
Stock = 300
firing = false
script.Parent.Name = name.. " (".. Clip.. "/".. Stock.. ")"
script.Parent.Activated:connect(function()
	if Clip >= 1 and fire == true then
		if Type == "Auto" then
			repeat Clip = Clip - 1
				local load = player.Character.Humanoid:LoadAnimation(script.Parent.Anims.R15Shoot)
				load:Play()
				firing = true
				local bullet = Instance.new("Part", workspace)
				bullet.Position = script.Parent.Handle.Position
				bullet.CanCollide = false
				bullet.Material = "Neon"
				bullet.BrickColor = BrickColor.new("New Yeller")
				bullet.Size = Vector3.new(.2,.2,.7)
				bullet.CFrame = CFrame.new(script.Parent.Handle.Position,mouse.Hit.p)
				local v=Instance.new("BodyVelocity", bullet)
				v.Velocity = bullet.CFrame.lookVector*500
				bullet.Touched:connect(function(hit)
					if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= player.Character then
						hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
						bullet:Destroy()
					end
				end)
				script.Parent.Name = name.. " (".. Clip.. "/".. Stock.. ")"
				script.Parent.ExtraParts.Flash1.Transparency = 0
				script.Parent.ExtraParts.SlidePos1.Transparency = 1
				script.Parent.ExtraParts.SlidePos2.Transparency = 0
				wait(rate/5)
				script.Parent.ExtraParts.Flash2.Transparency = 0
				wait(rate/5)
				script.Parent.ExtraParts.Flash1.Transparency = 1
				script.Parent.ExtraParts.Flash2.Transparency = 1
				script.Parent.ExtraParts.SlidePos1.Transparency = 0
				script.Parent.ExtraParts.SlidePos2.Transparency = 1
				wait(rate/5)
				wait(rate/5)
				wait(rate/5)
				game.Debris:AddItem(bullet,10)
			until Clip < 1 or firing == false
		elseif Type == "Auto" then
			local load = player.Character.Humanoid:LoadAnimation(script.Parent.Anims.R15Shoot)
				load:Play()
				Clip = Clip - 1
				local bullet = Instance.new("Part", workspace)
				bullet.Position = script.Parent.Handle.Position
				bullet.CanCollide = false
				bullet.Material = "Neon"
				bullet.BrickColor = BrickColor.new("New Yeller")
				bullet.Size = Vector3.new(.2,.2,.7)
				bullet.CFrame = CFrame.new(script.Parent.Handle.Position,mouse.Hit.p)
				local v=Instance.new("BodyVelocity", bullet)
				v.Velocity = bullet.CFrame.lookVector*500
				bullet.Touched:connect(function(hit)
					if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= player.Character then
						hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
						bullet:Destroy()
					end
				end)
				script.Parent.Name = name.. " (".. Clip.. "/".. Stock.. ")"
				script.Parent.ExtraParts.Flash1.Transparency = 0
				script.Parent.ExtraParts.SlidePos1.Transparency = 1
				script.Parent.ExtraParts.SlidePos2.Transparency = 0
				wait(rate/5)
				script.Parent.ExtraParts.Flash2.Transparency = 0
				wait(rate/5)
				script.Parent.ExtraParts.Flash1.Transparency = 1
				script.Parent.ExtraParts.Flash2.Transparency = 1
				script.Parent.ExtraParts.SlidePos1.Transparency = 0
				script.Parent.ExtraParts.SlidePos2.Transparency = 1
				wait(rate/5)
				wait(rate/5)
				wait(rate/5)
				game.Debris:AddItem(bullet,10)
		end
	end
end)
script.Parent.Equipped:connect(function()
	script.Parent.Name = name.. " (".. Clip.. "/".. Stock.. ")"
	local load = player.Character.Humanoid:LoadAnimation(script.Parent.Anims.R15Hold)
	load:Play()
	script.Parent.Unequipped:connect(function()
		script.Parent.Name = name.. " (".. Clip.. "/".. Stock.. ")"
		load:Stop()
	end)
end)
script.Parent.Deactivated:connect(function()
	firing = false
end)
mouse.KeyDown:connect(function(key)
	if string.lower(key) == "r" and fire == true and Clip < MaxClip and script.Parent.Parent == player.Character then
		script.Parent.ExtraParts.SlidePos1.Transparency = 1
				script.Parent.ExtraParts.SlidePos2.Transparency = 0
		local load = player.Character.Humanoid:LoadAnimation(script.Parent.Anims.R15Reload)
				load:Play()
		local clone = script.Parent.ExtraParts.Mag:Clone()
		clone.Parent = nil
		script.Parent.ExtraParts.Mag.Weld:Destroy()
		fire = false
		wait(reload)
		script.Parent.ExtraParts.Mag:Destroy()
		script.Parent.ExtraParts.SlidePos1.Transparency = 0
				script.Parent.ExtraParts.SlidePos2.Transparency = 1
		clone.Parent = script.Parent.ExtraParts
		fire = true
		local amount = MaxClip - Clip
		if Stock >= amount then 
		Stock = Stock - amount
		Clip = Clip + amount
		script.Parent.Name = name.. " (".. Clip.. "/".. Stock.. ")"
		elseif Stock < amount then
			Clip = Clip + Stock
			Stock = 0
			script.Parent.Name = name.. " (".. Clip.. "/".. Stock.. ")"
		end
	end
end)

1 answer

✓ Accepted answer

Insert a Sound into the main part, where the bullet fires out of. This seems to work with TurboFusion's guns from my experience.

(Don't forget the SoundId in the Sound object.)

3 comments

0

So by inserting a sound, i would put sound:play()? And how would ik if its the main bullet because i think it would be on line 21?

0

When you say insert a sound do,you mean Sound:Play()? And how would ik what the main part is i think its line 21?

0

you rightClick on the part that fires, or maybe just on the Tool, and go to Insert Object, then select sound. You could also maybe do it so when you click, it does FireSound:Play()

This discussion is preserved as it was. New answers, comments, and votes are closed.