Basically what the title says,
Video for better understanding
Forgot to mention I’ve already tried doing SoundService:SetListener()
It didn’t work
Basically what the title says,
Video for better understanding
Forgot to mention I’ve already tried doing SoundService:SetListener()
It didn’t work
Updating post, is doing this allowed?
I’m not sure that there’s a direct property which you can modify to make that happen. Though something I had in mind was to make the sound global (parenting to the workspace) and then using a magnitude check via the Part
(which originally contained the sound) and the Character
of the player, then using the magnitude to pitch the sound.
You could probably hook it up to a .Heartbeat
or .RenderStepped
signal via the RunService service, though make sure it doesn’t affect performance. Here’s how I’d go about doing that:
Regular script in the workspace with the RunContext
set to Client
:
-- services
local runService = game:GetService("RunService")
local players = game:GetService("Players")
-- variables
local player = players.LocalPlayer
local originalPart = workspace:WaitForChild("THE_PART")
local sound = workspace:WaitForChild("THE_SOUND")
local maxDistance = 100 -- this is the max distance of the sound
-- functions
runService.RenderStepped:Connect(function()
local character = player.Character
if (not character) then
return
end
local characterPosition = character:GetPivot().Position
local originalPartPosition = originalPart.Position
local magnitude = (characterPosition - originalPartPosition).Magnitude
local percentage = 1 - math.clamp(magnitude / maxDistance, 0, 1)
sound.Volume = percentage
end)
I hope this helps you!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.