Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Audio Radius help?

Asked by 9 years ago

I am making a generator give off a hum with a player-made audio. How would I make a block give off the sound within say the radius of 10 studs? Why won't this work? A sound was inserted into a part, then then a local script was inserted into that.

1 local sound = Instance.new("Sound") 2 sound.SoundId = "http://www.roblox.com/asset/?id=xxx" 3 sound.Parent = script.Parent 4 sound:play()

1 answer

Log in to vote
0
Answered by
Wutras 294 Moderation Voter
9 years ago

First of all, you should capitalize the first letter of the :Play() function. But making it an exact radius of 10 studs could be made with a LocalScript in the PlayerGui. It will only affect the player and stop the audio when the player is 10 studs away from it.

Put this into the script:

for _, v in pairs(game.Players:GetChildren()) do
if v:IsA("Player") then
    script.LocalScript:Clone().Parent = v.PlayerGui
end

Put this into the LocalScript:

while wait() do
while script.Parent.Parent.Character do
if (script.Parent.Character.Torso.Position - workspace.Partname.Position).magnitude <= 10 then
    workspace.Partname.Sound:Play()
repeat wait() until (script.Parent.Character.Torso.Position - workspace.Partname.Position).magnitude > 10
    workspace.Partname.Sound:Stop()
end
    wait()
end
end

These code lines are not really good in my opinion and I could do them better, but I'm not having much time right now. Anyways, I hope you get the hang of it and can do your script.

Ad

Answer this question