I want to know how to change the volume of a locally played sound but this just doesn’t work. My script is below.
-- "sound" is the Instance which is a Sound that is played locally.
for i = 1, 100 do
sound.Volume = sound.Volume - 0.01
end
sound:Destroy()
Loops without any cooldown would uh, literally make the sound go Y e e t to 0
You have to encase it with a Wait()
of some sort for it to slowly decrease in Volume:
local RunService = game:GetService("RunService")
for i = 1, 100 do
sound.Volume = sound.Volume - 0.01
RunService.Heartbeat:Wait()
end
sound:Destroy()
Still, the volume doesn’t even change.
What kind of script are you exactly using to play the Sound from? And where is it located?
A localscript inside of StarterPlayerScripts
. The sound is located in SoundService.
Perhaps check for any printing?
print("Call this before starting the loop")
local RunService = game:GetService("RunService")
for i = 1, 100 do
print("Looping")
sound.Volume = sound.Volume - 0.01
RunService.Heartbeat:Wait()
end
print("Removing")
sound:Destroy()
It’s printing alright, but nothing happens to the volume still.
Can you check that the sound.Volume
property isn’t 0? Or that the Sound ID you’re attempting to play is valid?
Other than that I can’t think of anything else
Hi! Sorry for the extremely late reply, I just forgot to check your message. I tried checking if the sound.Volume
property isn’t nil, and it printed as 0.5
before the for loop. After the for loop, it prints as 0
but how loud the audio is still didn’t change. And yes, the sound does play and I can hear it clearly.
Definitely did not take 20 minutes for me to simply create a Baseplate Template on Studio
Unsure why it’s working for me, I just created a place and did the same thing & it worked fine for me
Maybe you can use this for reference as to why it isn’t working:
SoundTestMoment.rbxl (28.9 KB)
I think that is because the sound is not locally played on that file.
What? I have it call Play()
on the client, so I’m unsure as to why you’re stating that
Even still, if you set the Playing
property to true on the server then lower the Volume
on the client it works fine for me
I think I’ll just play the sound using :Play()
instead of :PlayLocalSound()
.
You could’ve just said that instead
I don’t think you can use PlayLocalSound()
for this particular instance, which is why I mainly use Play()
to play Sounds both server/client sided