Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making sound tone down in volume after time script [isn't working?]

Asked by 9 years ago
local time = game.Lighting.TimeOfDay
local t = tonumber(string.sub(time,1,2)..string.sub(time,4,5)..string.sub(time,7,8)) --convert time to a number

if t >= 73000 then
    for i = .2,0,-.001 do --loop that turns music down over 2 seconds
        wait(.01)
        script.Sunset.Volume = i
            if i == 0 then
                script.Sunset:Stop()
                break --is this necessary?
            end
    end 

script.Dawn:Play()

elseif t >= 200000 then
    for i = .2,0,-.001 do --same for this  ! 
        wait(.01)
        script.Dawn.Volume = i
            if i == 0 then
                script.Dawn:Stop()
                break
            end
    end

script.Sunset:Play()

end

I tried this on a multiplayer server, and the song for Dawn wouldn't tone down to 0 volume when the time came along. Any ideas?

ps: Huge thanks to the other guy that suggested I turned the strings into numbers so I could compare them using tonumber.

0
You're welcome! By the way, wait() has a minimum argument: 0.03. Anything below that is the same as wait(). aquathorn321 858 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

While I'm trying to figure it out, here's what I made from scratch.

local time = game.Lighting.TimeOfDay
local t = tonumber(string.sub(time,1,2)..string.sub(time,4,5)..string.sub(time,7,8)) --convert time to a number

if t >= 73000 and t < 200000 then
for i = .2,0,-.001 do
wait()
script.Sunset.Volume = i
end
script.Sunset:Stop()
script.Sunset.Volume = .2
script.Dawn:Play()

elseif t >= 200000 then
for i = .2,0,-.001 do
wait()
script.Dawn.Volume = i
end
script.Dawn:Stop()
script.Dawn.Volume = .2
script.Sunset:Play()
end
1
You should tab your scripts, It makes it easier to read. If you say it's unnecessary, I got that tip from BlueTaslem. EzraNehemiah_TF2 3552 — 9y
0
It's unnecessary :P aquathorn321 858 — 9y
0
I didn't even think about changing the volume back to .2, Thanks again. Also, I'm working on it now :P konichiwah1337 233 — 9y
0
I think that's more 'common-sense' rather than a tip, Lord... DigitalVeer 1473 — 9y
View all comments (2 more)
0
Seems my code works for me. Does it give you any error? are you sure the code is even running? is it looped? aquathorn321 858 — 9y
0
One problem you might come across is that when the code first runs: it expects a sound to be playing. that means if the first if statement is true, it will loop without playing a sound but rather just manipulating the volume, and then it will play the dawn sound. I suggest you start the game with one sound already playing and the time set at an appropriately in reference to the song. aquathorn321 858 — 9y
Ad

Answer this question