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

Audio won't restart once it hits certain time position. Why?

local music = workspace.Music1

music.Playing = true

if music.TimePosition == 60 then

music.TimePosition = 0

end

Trying to make a script that restarts the song once it hits the 1 minute mark, but when I went to test it it didn't restart. I don't know why. Sorry if it's obvious why.

1 comment

0

try doing musci:Stop() then music:Play() thats a guess i dont know if that will really work

3 answers

You had to add a while loop. If you have the if statement on its own, the script will not constantly check if the music hit 60 seconds, it will only check once.

local music = workspace.Music1

music.Playing = true
while wait(1) do
	if music.TimePosition == 60 then
		music.TimePosition = 0
	end
end

The script wont restart as it is not in a loop. As for why it doesn't restart with the time position its because the time position is the time it starts, and doesn't change as the music is running (If you don't believe me then check the music1 properties when playing the game and you will see time position does not change.)

The following script below should solve the issue:

local music = workspace.Music1 -- Locates the music.

music.Playing = true -- Starts playing the music.

while true do -- A loop that runs forever as true is always true.
wait(60) -- Time to wait before it stops.
music:Stop() -- Stops the music.
music.TimePosition = 0 -- Restarts the music.
music:Play() -- Plays the music again
--This loops runs forever.
end

These questions are simple to fix. It is just most likely that the property 'Loop' is not checked. Either way, try this script instead.

local Music = workspace.Music1 
Music.looped = true --This loops the song
Music:Play() 

Hope I helped!

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