Hello there!
I’m using Roblox’s random explosion generator tutorial, and I want to know how I can make an explosion sound play at an explosion while it’s in workspace. But, I don’t want the sound just playing everwhere, like music. How can I make the sound play like this?
Here’s the script:
local function explodePart(part)
local number = math.random(1,8)
if number == 1 then
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = game.Workspace
end
end
local children = game.Workspace:GetChildren()
while true do
for _, child in ipairs(children) do
if child.Name == "Part" then
explodePart(child)
end
end
wait(1)
end
I see. However, I have a ton of parts labeled Part (hence why I chose to make the explosions at parts named that), and that would be so many parts. My thoughts now are maybe just making a sound, and parenting it to the position of the explosion part?
Unfortunately you can’t move sounds based on either vector3 or CFrame. In theory, if you just modify your code like so:
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = game.Workspace
Sound.Parent = part
DebrisService:Add(Sound, .5)
or something of sorts, it should work. Remember, your explosion is going to be at the position of a part, meaning a part will exist. That being said, you’ve got the part, since you got its position. Just add the sound to it.