Bullet crack noise

  1. What do you want to achieve?

I’ve been trying to achieve bullet crack noise, if you don’t know what is that then you can watch this video ----> Bullet Fly By - YouTube

  1. What is the issue?

I’ve tried scripting it and it didn’t turn out to be working (btw it’s only testing script so no audio would play but the script should print “booya” if the bullet is close enough)

for _, bullet in pairs(workspace.Bullets:GetChildren()) do

	local dist = (game.Players.LocalPlayer.Character.PrimaryPart.Position - bullet.Position).Magnitude
		
		print(dist)
		
		if dist <= maxDistance then
			print("booya")
		end
	end
  1. What solutions have you tried so far?

I’ve tried looking in every site that has roblox scripting support, such as:
reddit,
scriptinghelpers.org,
roblox dev hub,
but they didn’t seem to have any solutions for my problem, so if you know how to fix it or what did I do wrong, please tell me what to do

Are you doing this in a renderstepped loop or otherwise looping it to constantly check for bullets? You could also do a chidadded event.

1 Like

I’ve tried putting it in renderstepped and repeat until loop and both didn’t work

As Hailey said you have to constantly iterate that function in loop. I tried simple while wait() loop and it worked for me. Try to use that code.

local maxDistance = 6

while wait() do
	for _, bullet in pairs(workspace.Bullets:GetChildren()) do
	
		local dist = (game.Players.LocalPlayer.Character.PrimaryPart.Position - bullet.Position).Magnitude
	
		if dist <= maxDistance then
			print("booya")
		end
	end
end

oh yeah, I forgot to mention that I use partcache, if that changes anything

you could do some really hacky stuff with collision groups and raycasting