PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TimePosition

Sound

double

Shows the progress in seconds of the Sound. Can be changed to move the playback position of the sound. If the sound is already playing then playback will snap to the specified position. If it is not playing the Sound will begin playback at the set position when the sound is next played.

As a Sound is played, TimePosition increases at a rate of Sound/PlaybackSpeed per second. Once TimePosition reaches Sound/TimeLength the Sound will stop unless it is looped. This means, unless Sound/Looped is set to true setting TimePosition to a value equal or greater to Sound/TimeLength will stop the sound.

Note that setting TimePositio` to a value greater than the length in a looped track will not cause it to wrap around. If that behavior is desired the developer should do the following.

if newPosition >= sound.TimeLength then
	newPosition = newPosition - sound.TimeLength
end
sound.TimePosition = newPosition

Setting TimePosition to a value less than zero currently does not influence playback, but this behavior should not be relied upon.


Code Samples


Sound TimePosition

This sample demonstrates how Sound.TimePosition can be used to jump to particular points in an audio file both before and during Sound playback.

A Sound is created in the Workspace and set to start at 30 seconds in. During playback, it jumps forwards to 100 seconds and then back to the start (0 seconds).

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://301964312"

-- set the sound to start at 30 seconds
sound.TimePosition = 30

-- play the sound
sound:Play()

wait(5)

-- jump forwards to 100 seconds
sound.TimePosition = 100

wait(5)

-- jump back to the start
sound.TimePosition = 0