How do we add sounds onto parts?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am a beginner scriptor and I want to add a sound to a heavily modified Rufus14 weapon. The 2 sounds are meant to go off when a Bullet Hole is created to simulate an impact effect for a rocket launcher.

  2. What is the issue? Include screenshots / videos if possible!
    There isn’t any output (error nor warning) saying that the sound failed in any way, but the sound doesn’t play, they just don’t work when the parent is ‘hole.’ (a part created by ‘Makepart()’

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I have checked and all of the sounds were fine and working when I tested them in different areas. Is this a bug or spaghetti coding?

makebhole = function(pos, normal, size, color, parent, material, debristime)
	local hole = makepart(
		parent,
		Vector3.new(0.05, size, size),
		CFrame.new(pos),
		false,
		false,
		"buIlethole"
	)
	hole.CanQuery = false
	hole.CanTouch = false
	hole.Material = material
	hole.BrickColor = color
	hole.Shape = Enum.PartType.Cylinder
	hole.CFrame = CFrame.lookAt(pos, pos+normal) * CFrame.Angles(math.pi/2,0,math.pi/2)
	hole.Transparency = 1
	playremovesound("explodenear", hole, 0.5+math.random(-5,5)/70, 0.1)
	playremovesound("explodefar", hole, 0.5+math.random(-5,5)/70, 0.1)
	local explosion = Instance.new('Explosion')
	explosion.BlastPressure = 50000 -- Completely safe explosion
	explosion.BlastRadius = 15
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.Position = hole.Position
	explosion.Parent = workspace
	explosion.Visible = true
	explosion.DestroyJointRadiusPercent = 0.333333333
	
	if parent.Anchored then
		hole.Anchored = true
	else
		hole.Anchored = true
	end
	if debristime then
		debris:AddItem(hole, debristime)
	end
	return hole
end

Sound Effect Data

local sfxdata = { --dont repeat names (id, vol, rollmin, rollmax, playonremove)
	["impact1"] = {"341519743", 4, 0.2, 60, true},
	["impact2"] = {"1489924400", 4, 0.2, 60, true},
	["impact4"] = {"1476374050", 4, 0.2, 60, true},
	["impact3"] = {"3802437361", 4, 0.2, 60, true},
	["bhf1"] = {"3744371091", 1, 1, 60, true},
	["bhf2"] = {"3744371584", 1, 1, 60, true},
	["bhf3"] = {"3744371864", 1, 1, 60, true},
	["snap"] = {"4086190876", 1, 1, 60, true},
	["bone"] = {"4086172420", 1, 1, 60, true},
	["pull"] = {"7127178040", 5, 1, 60, true},
	["supersonic1"] = {"6113434720", 10, 0.035, 1, true},
	["supersonic2"] = {"3809084884", 10, 0.035, 1, true},
	["shootnormal"] = {"5700090398", 20, 0.5, 10, true},
	["shootaway"] = {"5919825273", 5, 2.5, 1200, true},
	["click"] = {"132464034", 4, 1, 60, true},
	["equip"] = {"3742321449", 2.5, 1, 60, true},
	["reload"] = {"5445945972", 2, 1, 60},
	["reload2"] = {"6808988208", 2, 1, 60},
	["explodenear"] = {"9114087096", 10, 1, 200, true},
	["explodefar"] = {"7423520828", 10, 1, 2000, true}
}

and the main PlayRemoveSound core

playremovesound = function(name, parent, speed, timepos)
	local thesound = currentsounds[name]
	if not thesound then
		print(name, "sound not found")
		return
	end
	thesound.Parent = parent
	thesound.PlaybackSpeed = speed
	thesound.TimePosition = timepos or 0
	thesound.Parent = nil
end

I just need guidance.

try going into the server while playing and see if the bullet holes appear on the server side and not just the client

Hi, the problem is within your last function:

The playremovesound function does basically what it actually has to do, create the sound, configure it, and then delete it. But you are trying to parent a table value from a module into the part. Your function currently looks something like this in action:

  1. Initialize thesound variable with the table data.
  2. Check for errors.
  3. Parent the variable to the desired part. (Wont do anything since thesound is not a game part)
  4. Configure the variable. (Wont do anything, same case here)
  5. Remove the parent. (Nothing new, it doesnt do anything)

But now how do we actually turn this table into a part/sound? Our variable currently returns these: (For the different function calls)

So now we have the ID of the sound that we want to play, we just have to turn it into an instance, which is pretty simple:

playremovesound = function(name, parent, speed, timepos)
	local thesound = currentsounds[name]
	if not thesound then
		print(name, "sound not found")
		return
	end
	
	local soundInstance = Instance.new("Sound")
	soundInstance.SoundId = thesound[1]
	soundInstance.PlayOnRemove = thesound[5]
	soundInstance.Parent = parent
	soundInstance.PlaybackSpeed = speed
	soundInstance.TimePosition = timepos or 0
	soundInstance:Destroy()
end

This function now creates a new instance which has the class of Sound, sets its soundId variable to the set value in the table (first value), sets the PlayOnRemove variable to the set value (fifth value), parents it to the part, configures it, then destroys it, so that the sound will play. (The PlayOnRemove is set to true which means if we destroy the instance the sound will play)

Let me know if something isnt clear or you have any more questions regarding this issue.

PS: I havent tested this, so it might not be functionable, but just message me back.