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

Need help! Time Length in a music randomizing script not working?

Asked by 6 years ago

So, I have this music randomizer script that runs on sound IDs, but it does not function correctly. To go into more detail, the Wait_Time variable uses a time length, but instead of playing the entire song and then moving on, it automatically thinks its done and gives about 0.5 seconds worth of the song, and that's only because of lines 10 - 13.. I seriously need help on this script, any answer would be very helpful.

Here is the script:

song_ID = {130776739,327081386,1375384985,685388224,755156652,214902446,437141803} 
randomizer = true 
song = Instance.new("Sound",workspace) song.Name = "TheLionLiar's DJ"
Wait_Time = song.TimeLength
inc = .01 




asset_ID = "http://www.roblox.com/asset/?id="
function choose(tab) local obj = tab[math.random(1,#tab)] return obj end
function play(s) if s:IsA("Sound") then local o = s.Volume s.Volume = 0 s:play() for i = 0,o,inc do wait() s.Volume = i end s.Volume = o end end
function stop(s) if s:IsA("Sound") then local o = s.Volume for i = o,0,-inc do wait() s.Volume = i end s:stop() s.Volume = o end end


local h = Instance.new("Hint",workspace)
local Tool = game.ReplicatedStorage.tools.BoomBox 
local Handle = Tool:WaitForChild("Handle")
local Remote = Tool:WaitForChild("Remote")
local Sound = Handle:WaitForChild("Sound")



counter = 1
if #song_ID > 0 then
while true do
wait()

if randomizer then song.SoundId = asset_ID..""..choose(song_ID) else song.SoundId = asset_ID..""..song_ID[counter] end
play(song)
h.Text = "Song is being played..."
wait(Wait_Time)
h.Text = "Song Finished! TheLionLiar is picking a song for you..."
stop(song)
if counter >= #song_ID then counter = 1 else counter = counter + 1 end


end
end




0
Would you mind editing the script to indent it properly? It's a bit hard to read without the indentation. ultrasonicboomer 85 — 6y
0
ok TheLionLiar 39 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

Since you set the wait time to the TimeLength at the beginning of the script, it doesn't change when you change the song (it keeps it at whatever the TimeLength was at that instant). So, to fix this, you can replace

wait(Wait_Time)

with

wait(song.TimeLength)

to wait the TimeLength of that specific song.

0
thx!!! TheLionLiar 39 — 6y
0
Accepting the answer would be much appreciated if it helped mattscy 3725 — 6y
0
done TheLionLiar 39 — 5y
Ad

Answer this question