I am trying to do simple fade out effect on music after player leaves area
For some reason roblox can print v.volume but can’t change it. Here’s output:
14:34:19.681 0.5 - Music:25
14:34:19.681 0.5 - Music:11
14:34:19.681 volume is not a valid member of Sound "Players.CEHATOP_PYCC.PlayerScripts.Music.Calm_Positive" - Music:12
Code:
local ZoneService = require(game:GetService("ReplicatedStorage").Zone)
local Areas = workspace:WaitForChild("AREAS")
local zone = ZoneService.new(Areas.Tension)
local MusicList = script:GetDescendants()
local CalmList = {script.Calm_Neutral, script.Calm_Positive}
local function SoftStop(music)
repeat
print(music.volume)
music.volume -= 0.1
task.wait(0.1)
until music.volume == 0
music:Stop()
end
zone.playerEntered:Connect(function(player)
CalmList[math.random(1, #CalmList)]:Play()
end)
zone.playerExited:Connect(function(player)
for i, v in pairs(MusicList) do
if v.IsPlaying == true then
print(v.volume)
SoftStop(v)
end
end
end)