How to restart an audio

When I change the sound id of a sound in sound service then set its time position to 0, it doesn’t reset. I tried stopping it ( audio:stop() ) and then starting it again and that didn’t even work. need some help.

music.SoundId = “rbxassetid://” …map3.Music
music.TimePosition = 0
music:stop() music:play()
music.Volume = map3.MusicVol
music.Val = map3.MusicVol

is music a sound instance? do you get any errors?

yes it is, and not getting any errors

What does it do, does the original song just keep playing and repeating?

the music changes but its time position doesnt, it’ll just play from where the other audio one left off

You’re changing SoundId to map3.Music and not map3.Music.Value.

1 Like

Let me explain more. The music.val is a number value parented in the sound instance in sound service for a mute button to work, it has nothing to do with time position.

map3.music is a sound id itself from a module script containing maps, map sound ID’s and volumes for those sounds.

The script I wrote above is changing the music sound id (in sound service) to a new ID returned from a module.

simply,

local music = -- put your location of the music object here

music.TimeLength = 0 -- sets the music to beginning


Try TimePosition = TimeLength, this’ll end the song and make it start from the beginning. (If you have looped on.)
image
Or play then timeposition it.

music.SoundId = “rbxassetid://” …map3.Music
music:Play()
music.TimePosition = 0

nope. I tried them together and it still didn’t work (is looped)

music.TimePosition = music.TimeLength
music.SoundId = “rbxassetid://” …map1.Music
music:Play()
music.TimePosition = 0
music.Volume = map1.MusicVol
value.Value = music.Volume

edit: same code but for map1

i thought timelength can’t be manipulated…? and no this didn’t work

Is this a local script? characters


Screenshot (126)
Screenshot (127)

refer to the following images. its a normal script located in workspace

The only way I’ve handled sounds in the past is by cloning them, parenting them into workspace and then playing that cloned sound.

Have you tried doing something like this:

--Set the sound ID, and then:
sound:Stop()
sound.TimePosition = 0
--Whatever other tweaks you need to do
sound:Play()

I’m not super familiar with sounds, but it seems like your timeposition change is probably happening, but another script ignores it and moves the time along while the sound is playing.

That actually worked, thanks. Still not actually sure how mine didn’t work tho

Aw man, I was gonna say timeposition. I forgot the difference between sound.TimeLength and sound.TimePosition.

:troll:

1 Like