Hello, I’m trying to make a script volumes up a sound, but really smooth, I tried with TweenService, but it didn’t worked.
for i = 0,1,0.1 do
script.sound.Volume = script.sound.Volume + i
wait(0.1)
end
--Attempt with tweenservice
local TweenService = game:GetService("TweenService")
TweenService:Create(script.sound, TweenInfo.new(1), {Volume = 1})
I am generally confused about why do you try to use TweenService to increase the volume of a sound. You can simply just run the code you entered above without TweenService. Here is an example:
for 1,10 do
script.sound.Volume = script.sound.Volume + 0.1
wait(0.5)
end
Yes, I was trying to know, as tweenservice works for a lot of stuff, like, fading out and in, I was just trying to know if it could work for this! Seems like no.
As I know TweenService is mostly used for Workspace object manipulation. For example to make an object to move in different axises etc. I don’t think sound decreasing and increasing might be possible with TweenService at all. The types of properties you can Tween with TweenService are:
You need to play the tween in order it for to work.
The fixed code would be as follows:
local TweenService = game:GetService("TweenService")
local Tween_Info = TweenInfo.new(1)
local Tween_Goal = {Volume = 1}
local Sound = script.sound
local Tween = TweenService:Create(Sound, Tween_Info, Tween_Goal)
Tween:Play()
Please read my reply again, I clearly state you need to play the tween in order it for to work.
The original code sample you gave us, shows you not playing it. Only creating it.
local Rs = game:GetService("RunService")
local Sound = script.Sound
function lerp(a,b,t)
return a + (b-a)*t
end
function TurnUpMusic(Volume)
for i = 1, 101, 1 do
Rs.Heartbeat:Wait(2)
local Value = lerp(Sound.Volume, Volume, (i-1)/100)
Sound.Volume = Value
end
end