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
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
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
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