Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

TimeLength is really annoying me.. help?

I've been trying to script this all day but whenever I use TimeLength in studio it works perfectly, but in-game it doesn't work. I've tried IsPlaying, IsPaused and I can not figure out how to make this work. Usually, the song would play then end and a new song will start (this is what it does in studio) but in-game it plays, then stops, a new song plays, then stops, almost like its ignoring the wait.

local ContentProvider = game:GetService("ContentProvider")

ids = {313144336,325559646,304989710,283801001,324762701,255854737,199327080,322868071,149753125,187145984,142460836,272156573,311303451,319101689,325944798,255763463,313800522,300622704,254695481,305055144,229944246,274427825,300411751,155623794}

local SoundInstance = game.Workspace.VritixConsole.MainWall.SurfaceGui.ASong
local on = script.Parent.On
x =1

for i,v in pairs(ids) do
    ContentProvider:Preload("rbxassetid://" .. v) 
end


function run()

while true do
wait(2)
local playing = ids[math.random(1, #ids)]
song =  SoundInstance
song.SoundId = "rbxassetid://"..playing
song:Play()
for i=1,10 do
song.Volume = song.Volume + 0.1
wait(0.1)
end
wait(song.TimeLength)
song:Stop()
wait(0.5)
end
end
	
function click()
	 song=SoundInstance
	   if on.Value == false then
		x = 1
		game.Workspace.VritixConsole.AUTO.SurfaceGui.TextButton.Text = "AUTO DJ : ON"
		on.Value = true
		run()
	else
	if on.Value == true then
		on.Value = false
		x = 2
		game.Workspace.VritixConsole.AUTO.SurfaceGui.TextButton.Text = "AUTO DJ : OFF"
		for i=1,10 do
			song.Volume = song.Volume - 0.1
			wait(0.1)
		end
		song:Stop()
	end
	end
end
script.Parent.MouseButton1Down:connect(click)


2 comments

0

Try doing a 'repeat wait() until song.Ended' instead of wait(song.TimeLength)

0

Ended event doesn't work in-game.

1 answer

So your solution didn't work? What a shame. Stop looking for TimeLength on the server

Why? The server doesn't load any sounds and doesn't know how long they last.

A possible solution could be to use Sound.Ended

local ContentProvider = game:GetService("ContentProvider")

ids = {313144336,325559646,304989710,283801001,324762701,255854737,199327080,322868071,149753125,187145984,142460836,272156573,311303451,319101689,325944798,255763463,313800522,300622704,254695481,305055144,229944246,274427825,300411751,155623794}

local SoundInstance = game.Workspace.VritixConsole.MainWall.SurfaceGui.ASong
local on = script.Parent.On
x =1

for i,v in pairs(ids) do
    ContentProvider:Preload("rbxassetid://" .. v) 
end


function run()

while true do
wait(2)
local playing = ids[math.random(1, #ids)]
song =  SoundInstance
song.SoundId = "rbxassetid://"..playing
song:Play()
for i=1,10 do
song.Volume = song.Volume + 0.1
wait(0.1)
end
song.Ended:wait()
song:Stop()
wait(0.5)
end
end

function click()
     song=SoundInstance
       if on.Value == false then
        x = 1
        game.Workspace.VritixConsole.AUTO.SurfaceGui.TextButton.Text = "AUTO DJ : ON"
        on.Value = true
        run()
    else
    if on.Value == true then
        on.Value = false
        x = 2
        game.Workspace.VritixConsole.AUTO.SurfaceGui.TextButton.Text = "AUTO DJ : OFF"
        for i=1,10 do
            song.Volume = song.Volume - 0.1
            wait(0.1)
        end
        song:Stop()
    end
    end
end
script.Parent.MouseButton1Down:connect(click)

But personally I don't expect it to work for the same reason as the TimeLength issue.

This discussion is preserved as it was. New answers, comments, and votes are closed.