Hello, I’m trying to make a sound start playing only after a certain distance away from a sound part. I’ve tried messing with RollOff Distances and I cant quite seem to figure it out. Does anybody have any idea on how I can achieve this goal?
Here is a quick image representation of what I mean, as it is a bit hard to explain in text.
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
Part = workspace.Part
YourSound = Part.YourSound -- Replace with the sound you want to use
MaxDistance = 10
SoundHeard = true
while true do
task.wait()
local Mag = (Char.HumanoidRootPart.Position - Part.Position).Magnitude
if Mag < MaxDistance and SoundHeard == true then
YourSound:Stop()
SoundHeard = false
else
SoundHeard = true
YourSound:Play()
end
end
-- Local Script
local RunService = game:GetService('RunService')
local Plr = game:GetService('Players').LocalPlayer
local Sound = workspace.Sound
local Part = workspace.Part
local Range = 34 -- got 34 by counting the studs in the picture
Sound:Play()
RunService.RenderStepped:Connect(function()
if Plr:DistanceFromCharacter(Part.Position) > Range then
Sound.Volume = .5
else
Sound.Volume = 0
end
end)