Sound

Show Deprecated

A Sound is an object that emits sound.

2D and 3D Sound

A sound placed in a BasePart or an Attachment will emit its sound from that part's BasePart.Position or the attachment's Attachment.WorldPosition. A sound exhibits the Doppler effect, meaning its frequency and pitch varies with the relative motion of whatever attachment or part it is attached to. The volume of the sound will be determined by the distance between the client's sound listener (by default the Camera position) and the position of the sound's parent. For more information on this see Sound.RollOffMode.

A sound is considered "global" if it is not parented to a BasePart or an Attachment. In this case, the sound will play at the same volume throughout the entire place.

Code Samples

Sound in the Workspace

1local sound = Instance.new("Sound")
2sound.SoundId = "rbxassetid://9120386436"
3sound.Looped = true
4sound.Parent = workspace
5sound:Play()
Music Playing Part

1local part = Instance.new("Part")
2part.Anchored = true
3part.Position = Vector3.new(0, 3, 0)
4part.BrickColor = BrickColor.new("Bright red")
5part.Name = "MusicBox"
6part.Parent = workspace
7
8-- create a sound
9local sound = Instance.new("Sound", part)
10sound.SoundId = "rbxassetid://9120386436"
11sound.EmitterSize = 5 -- decrease the emitter size (for earlier volume drop off)
12sound.Looped = true
13sound.Parent = part
14
15local clickDetector = Instance.new("ClickDetector")
16clickDetector.Parent = part
17
18-- toggle the sound playing / not playing
19clickDetector.MouseClick:Connect(function()
20 if not sound.IsPlaying then
21 part.BrickColor = BrickColor.new("Bright green")
22 sound:Play()
23 else
24 part.BrickColor = BrickColor.new("Bright red")
25 sound:Stop()
26 end
27end)

Summary

Properties

READ ONLY
NOT REPLICATED
NOT BROWSABLE

This property will be true when the Sound has loaded loaded from Roblox servers and is ready to play.

READ ONLY
NOT REPLICATED

This read-only property will return true when the Sound is not playing.

HIDDEN
READ ONLY
NOT REPLICATED

This read-only property will return true when the Sound is playing.

HIDDEN
READ ONLY
NOT REPLICATED

A range denoting a desired loop-start and loop-end within the Sound.PlaybackRegion, in seconds.

This sets whether or not the Sound repeats once it has finished when it is playing.

When true, the Sound will play when it is removed from the game, by parenting the Sound or one if its ancestors to nil.

A number between 0 and 1000 indicating how loud the Sound is currently playing back.

READ ONLY
NOT REPLICATED

A range denoting a desired start (min) and stop (max) time within the Sound.TimeLength, in seconds.

If true, this property gives your Sound access to to the Sound.PlaybackRegion and Sound.LoopRegion properties, which can more-accurately control its playback.

NOT BROWSABLE

Determines the speed at which a Sound will play, with higher values causing the sound to play faster and at a higher pitch.

NOT REPLICATED

Indicates whether the Sound is currently playing.

NOT REPLICATED

The maximum distance, in studs, a client's listener can be from the Sound\s origin and still hear it. Only applies to Sounds parented to a Part or Attachment (3D sounds).

NOT REPLICATED

The minimum distance, in studs, at which a 3D Sound (direct child of a BasePart or Attachment) will begin to attenuate (decrease in volume).

NOT REPLICATED

Controls how the volume of a 3D Sound (parented to a BasePart or Attachment) behaves as the distance between the listener and sound's parent changes.

The SoundGroup that is linked to this Sound. Volume and SoundEffects applied to this sound group will pass onto the sound. A sound can only be in one sound group at a time.

This property is the content ID of the sound file a Sound object is associated with. Once a sound has been uploaded to Roblox the content ID can be found in the uploaded sound's URL.

The length of the Sound in seconds. If the Sound is not loaded, this value will be 0.

READ ONLY
NOT REPLICATED

Shows the progress in seconds of the Sound. Can be changed to move the playback position of the Sound both before and during playback.

NOT REPLICATED

The volume of the Sound. Can be set between 0 and 10. Defaults to 0.5.

Events

DidLoop(soundId: string, numOfTimesLooped: number): RBXScriptSignal  

Event that fires whenever the Sound loops. Returns soundId and numOfTimesLooped, giving the contentID of the sound and the number of times looped respectively.


Fires when the Sound has completed playback and stopped.


Fires when the Sound is loaded.


Fires whenever the Sound is paused using Sound:Pause().


Fires whenever the Sound is played using the Sound:Play() function.


Fires when the Sound is resumed using Sound:Resume().


Fires when the Sound is stopped due to the Sound:Stop() function.

Methods

Pause(): void  

Sets Sound.Playing to false. This pauses the playback of the Sound if the sound is playing. As Sound.TimePosition is not reset ,when the Sound is resumed it will continue from its previous position.

Play(): void  

Plays the Sound. Sets Sound.TimePosition to the last value set by a Script (or 0 if it has not been set), and then sets Sound.Playing to true.

Resume(): void  

Resumes the Sound. Sets Sound.Playing to true. Does not alter Sound.TimePosition and thus can be used to resume the playback of a sound stopped using Sound:Pause().

Stop(): void  

Stops the Sound. Sets Sound.Playing to false then sets Sound.TimePosition to 0.

Properties

ChannelCount

Read Only
Not Replicated
Not Browsable

IsLoaded

Read Only
Not Replicated

This property will be true when the Sound has loaded loaded from Roblox servers and is ready to play.

In Roblox, audio files are not stored in games themselves but hosted on the Roblox servers and referenced by the Sound.SoundId property. This means that they need to be downloaded to a client's device before they can be played. This can take a while depending on the user's internet connection, the length of the sound and the number of other objects that need to be loaded.

Developers can use the Sound.IsLoaded property and the Sound.Loaded event if they wish to verify a sound has loaded before playing it.

IsPaused

Hidden
Read Only
Not Replicated

This read-only property will return true when the Sound is not playing. Note that this property will not only return true once a sound has been paused using the Sound:Pause() function but also if it has been stopped using the Sound:Stop() function or never been played.

This property will only be true when Sound.IsPlaying is false.

As IsPaused is read only it can not be used to stop the sound, Sound:Stop() and Sound:Pause() should be used instead.

IsPlaying

Hidden
Read Only
Not Replicated

This read-only property will return true when the Sound is playing.

This property can only be true when Sound.IsPaused is false.

As IsPlaying is read only it can not be used to play the sound, Sound:Play() should be used instead.

LoopRegion

A range denoting a desired loop-start and loop-end within the Sound's Sound.PlaybackRegion in seconds.

Looped

This sets whether or not the Sound repeats once it has finished when it is playing.

Looped sounds are suitable for a range of applications including music and background ambient sounds. The Sound.DidLoop event can be used to track the number of times as sound has looped.

PlayOnRemove

When true, the Sound will play when it is removed from the game.

Note the sound will play when the Instance.Parent property of the Sound or one of its ancestors is set to nil. This means all of the following will cause the sound to play when PlayOnRemove is true. Note, this includes Instance:Destroy() as the destroy function sets the parent to nil.


1sound:Destroy()
2sound.Parent = nil
3sound.Parent.Parent = nil
4

PlaybackLoudness

Read Only
Not Replicated

A number between 0 and 1000 indicating how loud the Sound is currently playing back.

This property reflects the amplitude of the Sound's playback in the instance of time it is read. Therefore, for most sounds it will fluctuate constantly. Due to this it can appear in the Roblox Studio properties window as 0, however when read by code in the command bar or Scripts it will return the correct value.

PlaybackRegion

A range denoting a desired start (min) and stop (max) time within the Sound.TimeLength, in seconds.

  • If PlaybackRegion.Min > 0, the sound begins to play from the PlaybackRegion.Min time.

  • If PlaybackRegion.Min < 0, the sound begins to play from 0.

  • If PlaybackRegion.Max > Sound.TimeLength, the sound stops at Sound.TimeLength.

  • If PlaybackRegion.Max < Sound.TimeLength, the sound stops at exactly that time.

  • If PlaybackRegion.Min == PlaybackRegion.Max, the PlayBackRegion is inactive.

PlaybackRegionsEnabled

Not Browsable

If true, this property gives your Sound access to to the Sound.PlaybackRegion and Sound.LoopRegion properties, which can more-accurately control its playback.

PlaybackSpeed

Not Replicated

Determines the speed at which a Sound will play. The greater the value the faster the sound will play back.

For example, a value of 2 will cause the Sound to play 2x faster, whereas a value of 0.5 will cause it to play 2x slower. When PlaybackSpeed is equal to 1, the sound will take Sound.TimeLength (in seconds) to complete.

Note that increasing the PlaybackSpeed of a sound will cause it to play at a higher pitch.

Playing

Not Replicated

Indicates whether the Sound is currently playing. This can be toggled, and this property will always replicate.

This property should not be confused with Sound.IsPlaying which is a read-only property. Playing can be set to true or false to start or stop the playback of a sound.

Note that when Playing is set to false, the Sound.TimePosition property of the sound will not reset. This means when the Playing is set to true again the audio will continue from the time position it was at when it was stopped. However, if the Sound:Play() function is used to resume the sound the time position will reset to 0.

RollOffMaxDistance

Not Replicated

The maximum distance, in studs, a client's listener can be from the Sound's origin and still hear it. Only applies to Sounds parented to a Part or Attachment (3D sounds).

How RollOffMaxDistance impacts the attenuation of a sound (manner in which it fades out) is dependent on the Sound.RollOffMode property. When RollOffMode is set to use an inverse type distance model (Inverse or InverseTapered) the RollOffMaxDistance will not effect the attenuation of the sound. This means that low values for RollOffMaxDistance will cause the sound to abruptly cut off when the listener reaches the RollOffMaxDistance. In most cases this is not desirable and developers are advised not to use low RollOffMaxDistance values.

When RollOffMode is set to a linear type distance model (Linear or LinearSquared) the sound will attenuate between Sound.EmitterSize and MaxDistance (with playback volume reaching zero at RollOffMaxDistance). This is less realistic, but in some cases allows attenuation to be handled in a more intuitive way.

RollOffMinDistance

Not Replicated

The minimum distance, in studs, at which a 3D Sound (direct child of a BasePart or Attachment) will begin to attenuate (decrease in volume).

Sounds parented to a BasePart or Attachment that are descendants of the Workspace are considered 3D sounds and their volume while playing is dependent on the distance between the client's sound listener (Camera position by default) and the Sound's parent. Three properties influence this behavior RollOffMinDistance, Sound.RollOffMaxDistance, and Sound.RollOffMode.

The way the Sound attenuates (fades out) after the distance between the listener and the sound exceeds the RollOffMinDistance is determined by the RollOffMode.

RollOffMode

This property sets how 3D Sounds attenuate (fade out) as the distance between the listener and the sound's parent increase. It can be set to one of the values of the RollOffMode enum.

The following code will set RollOffMode to Linear:


1sound.RollOffMode = Enum.RollOffMode.Linear
2

The different modes

Thee following options are available:

ModeDescription
InverseVolume attenuates from Sound/RollOffMinDistance in an inverse manner.
InverseTaperedA hybrid model. Follows the Inverse model when close to RollOffMinDistance and the Linear Square model when close to Sound/RollOffMaxDistance.
LinearVolume attenuates between RollOffMinDistance and Sound/RollOffMaxDistance with a linear relationship.
LinearSquareVolume attenuates between RollOffMinDistance and Sound/RollOffMaxDistance with a linear squared relationship.

Inverse vs Linear Distance Attenuation

By default sounds are set to use inverse distance attenuation (Enum.RollOffMode.Inverse) which mirrors how sounds attenuate in the real world. Under inverse distance attenuation, sounds will begin to attenuate once the distance between the listener and the Sound's parent exceeds RollOffMinDistance. The rate of attenuation depends on the emitter size, as sounds with larger EmitterSize's will attenuate at a slower rate. Inverse rate of inverse distance attenuation is further influenced by SoundService.RolloffScale.

RollOffMaxDistance will not effect attenuation under the inverse model but will cause the sound to cut off completely once this distance is reached. This can be particularly abrupt when using low values for max distance.

Linear distance attenuation works differently. Under linear distance attenuation the sound will attenuate between RollOffMinDistance and RollOffMaxDistance, falling silent once MaxDistance is reached. RollOffMinDistance still denotes the point at which the sound will begin attenuating. However, the audible volume at any point now depends on the point the listener is at between EmitterSize and MaxDistance. This means, in contrast to the inverse distance attenuation model, the audible volume of the sound will approach silence at MaxDistance point. This is less realistic, but may be more desirable in some cases.

SoundGroup

The SoundGroup that is linked to this Sound. SoundGroup.Volume and SoundEffects applied to this sound group will pass onto the sound. A sound can only be in one sound group at a time.

SoundGroups are used to manage the volume and effects of multiple Sounds at once. A Sound is added to a SoundGroup by setting the SoundGroup property of the sound.

SoundId

This property is the content ID of the sound file a Sound object is associated with. Once a sound has been uploaded to Roblox the content ID can be found in the uploaded sound's URL.

It's important to remember the URL is not the same as the content ID. It will work when pasted directly into the SoundId property of a Sound in Roblox studio, as Studio will automatically correct it, however if it is being set from a Script then the correct content ID will need to be used, using the number from the URL. For example:


1"https://www.roblox.com/catalog/9120386436" -- Web URL (will not work)
2"http://www.roblox.com/asset/?id=9120386436" -- Content ID (will work)
3"rbxassetid://9120386436" -- Content ID (alternative version, will work)
4

TimeLength

Read Only
Not Replicated

The length of the Sound in seconds. If the Sound is not loaded, this value will be 0.

This property is often used in conjunction with Sound.PlaybackSpeed to adjust the speed of a sound so it lasts for a specific duration (see examples). When Sound.PlaybackSpeed is equal to 1, the sound will take TimeLength seconds to complete.

TimePosition

Not Replicated

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 TimePosition 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.


1if newPosition >= sound.TimeLength then
2 newPosition = newPosition - sound.TimeLength
3end
4sound.TimePosition = newPosition
5

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

UsageContextPermission

Hidden
Not Replicated

Volume

The volume of the Sound. Can be set between 0 and 10. Defaults to 0.5

Note that if the Sound is a member of a SoundGroup its playback volume (but not the Volume property) will be influenced by the SoundGroup.Volume property of that SoundGroup. The effect of this is multiplicative, meaning that a sound will play at the same volume if its Volume is 0.1 and its SoundGroup's volume is 5 and vice-versa.

Events

DidLoop

Event that fires whenever the Sound loops. Returns soundId and numOfTimesLooped, giving the contentID of the sound and the number of times looped respectively.

When the Sound is stopped the looped counter resets meaning the next DidLoop event will return 1 for numOfTimesLooped.

Parameters

soundId: string

The Sound.SoundId of the Sound that looped.

numOfTimesLooped: number

The number of times the Sound has looped.


Code Samples

Loop a Number of Times

1local function loopNTimes(sound, numberOfLoops)
2 if not sound.IsPlaying then
3 sound.Looped = true
4 local connection = nil
5 connection = sound.DidLoop:Connect(function(_soundId, numOfTimesLooped)
6 print(numOfTimesLooped)
7 if numOfTimesLooped >= numberOfLoops then
8 -- disconnect the connection
9 connection:Disconnect()
10 -- stop the sound
11 sound:Stop()
12 end
13 end)
14 sound:Play()
15 end
16end
17
18local sound = Instance.new("Sound")
19sound.SoundId = "rbxassetid://0"
20
21loopNTimes(sound, 5)

Ended

Fires when the Sound has completed playback and stopped. Note this event will not fire for sounds with Sound.Looped set to true as they continue playing upon reaching their end.

This event is often used to destroy a sound when it has completed playback.


1sound:Play()
2sound.Ended:Wait()
3sound:Destroy()
4

This event only fires if the sound has reached its end. This means it will also not fire when the sound is stopped before playback has completed, for this use Sound.Stopped.

Parameters

soundId: string

The Sound.SoundId of the Sound that has ended.


Loaded

The Sound.Loaded event fires when the Sound is loaded.

Note this event will only fire at the time the sound is loaded. This means if it is listened for when the sound is already loaded it will not return. Therefore it is recommended to check Sound.IsLoaded prior to connecting to this event.

Parameters

soundId: string

The Sound.SoundId of the Sound that loaded.


Code Samples

Load Sound

1local function loadSound(sound)
2 -- Has the sound already loaded?
3 if not sound.IsLoaded then
4 -- if not, wait until it has been
5 sound.Loaded:Wait()
6 end
7end
8
9loadSound(workspace.Sound)

Paused

Fires whenever the Sound is paused using Sound:Pause().

As with Sound.Played, Sound.Resumed and Sound.Stopped only the respective sound function will cause the event to fire. This means that Pause will only fire when Sound:Pause() is called.

Parameters

soundId: string

The Sound.SoundId of the Sound that was paused.


Code Samples

Sound Functions

1-- create a sound
2local sound = Instance.new("Sound", game.Workspace)
3sound.SoundId = "rbxassetid://9120386436"
4
5if not sound.IsLoaded then
6 sound.Loaded:Wait()
7end
8
9-- listen for events
10sound.Played:Connect(function(_soundId)
11 print("Sound.Played event")
12end)
13
14sound.Paused:Connect(function(_soundId)
15 print("Sound.Paused event")
16end)
17
18sound.Resumed:Connect(function(_soundId)
19 print("Sound.Resumed event")
20end)
21
22sound.Stopped:Connect(function(_soundId)
23 print("Sound.Stopped event")
24end)
25
26sound:Play()
27print("play", sound.Playing, sound.TimePosition) -- play true 0
28
29task.wait(10)
30
31sound:Pause()
32print("pause", sound.Playing, sound.TimePosition) -- pause false 10
33
34task.wait(3)
35
36sound:Resume()
37print("play", sound.Playing, sound.TimePosition) -- play true 10
38
39task.wait(3)
40
41sound:Stop()
42print("stop", sound.Playing, sound.TimePosition) -- stop false 0
43
44task.wait(3)
45
46sound:Play()
47print("play", sound.Playing, sound.TimePosition) -- play true 0

Played

Fires whenever the Sound is played using the Sound:Play() function.

As with Sound.Stopped, Sound.Paused and Sound.Resumed only the respective sound function will cause the event to fire. This means that Played will only fire when Sound:Play() is called. This event will not fire if the Sound is played due to the sound being destroyed and Sound.PlayOnRemove being set to true.

Parameters

soundId: string

The Sound.SoundId of the Sound that was played.


Code Samples

Sound Functions

1-- create a sound
2local sound = Instance.new("Sound", game.Workspace)
3sound.SoundId = "rbxassetid://9120386436"
4
5if not sound.IsLoaded then
6 sound.Loaded:Wait()
7end
8
9-- listen for events
10sound.Played:Connect(function(_soundId)
11 print("Sound.Played event")
12end)
13
14sound.Paused:Connect(function(_soundId)
15 print("Sound.Paused event")
16end)
17
18sound.Resumed:Connect(function(_soundId)
19 print("Sound.Resumed event")
20end)
21
22sound.Stopped:Connect(function(_soundId)
23 print("Sound.Stopped event")
24end)
25
26sound:Play()
27print("play", sound.Playing, sound.TimePosition) -- play true 0
28
29task.wait(10)
30
31sound:Pause()
32print("pause", sound.Playing, sound.TimePosition) -- pause false 10
33
34task.wait(3)
35
36sound:Resume()
37print("play", sound.Playing, sound.TimePosition) -- play true 10
38
39task.wait(3)
40
41sound:Stop()
42print("stop", sound.Playing, sound.TimePosition) -- stop false 0
43
44task.wait(3)
45
46sound:Play()
47print("play", sound.Playing, sound.TimePosition) -- play true 0

Resumed

Fires when the Sound is resumed using Sound:Resume().

As with Sound.Played, Sound.Paused and Sound.Stopped only the respective sound function will cause the event to fire. This means that Resumed will only fire when Sound:Resume() is called.

Parameters

soundId: string

The Sound.SoundId of the Sound being resumed.


Code Samples

Sound Functions

1-- create a sound
2local sound = Instance.new("Sound", game.Workspace)
3sound.SoundId = "rbxassetid://9120386436"
4
5if not sound.IsLoaded then
6 sound.Loaded:Wait()
7end
8
9-- listen for events
10sound.Played:Connect(function(_soundId)
11 print("Sound.Played event")
12end)
13
14sound.Paused:Connect(function(_soundId)
15 print("Sound.Paused event")
16end)
17
18sound.Resumed:Connect(function(_soundId)
19 print("Sound.Resumed event")
20end)
21
22sound.Stopped:Connect(function(_soundId)
23 print("Sound.Stopped event")
24end)
25
26sound:Play()
27print("play", sound.Playing, sound.TimePosition) -- play true 0
28
29task.wait(10)
30
31sound:Pause()
32print("pause", sound.Playing, sound.TimePosition) -- pause false 10
33
34task.wait(3)
35
36sound:Resume()
37print("play", sound.Playing, sound.TimePosition) -- play true 10
38
39task.wait(3)
40
41sound:Stop()
42print("stop", sound.Playing, sound.TimePosition) -- stop false 0
43
44task.wait(3)
45
46sound:Play()
47print("play", sound.Playing, sound.TimePosition) -- play true 0

Stopped

Fires when the Sound is stopped due to the Sound:Stop() function.

As with Sound.Played, Sound.Paused and Sound.Resumed only the respective sound function will cause the event to fire. This means that Stopped will only fire when Sound:Stop() is called. Destroying a sound while it is playing will not cause this event to fire.

Parameters

soundId: string

The Sound.SoundId of the Sound that stopped.


Code Samples

Sound Functions

1-- create a sound
2local sound = Instance.new("Sound", game.Workspace)
3sound.SoundId = "rbxassetid://9120386436"
4
5if not sound.IsLoaded then
6 sound.Loaded:Wait()
7end
8
9-- listen for events
10sound.Played:Connect(function(_soundId)
11 print("Sound.Played event")
12end)
13
14sound.Paused:Connect(function(_soundId)
15 print("Sound.Paused event")
16end)
17
18sound.Resumed:Connect(function(_soundId)
19 print("Sound.Resumed event")
20end)
21
22sound.Stopped:Connect(function(_soundId)
23 print("Sound.Stopped event")
24end)
25
26sound:Play()
27print("play", sound.Playing, sound.TimePosition) -- play true 0
28
29task.wait(10)
30
31sound:Pause()
32print("pause", sound.Playing, sound.TimePosition) -- pause false 10
33
34task.wait(3)
35
36sound:Resume()
37print("play", sound.Playing, sound.TimePosition) -- play true 10
38
39task.wait(3)
40
41sound:Stop()
42print("stop", sound.Playing, sound.TimePosition) -- stop false 0
43
44task.wait(3)
45
46sound:Play()
47print("play", sound.Playing, sound.TimePosition) -- play true 0

Methods

Pause

void

Sets Sound.Playing to false. This pauses the playback of the Sound if the sound is playing. Unlike Sound:Stop() it does not reset Sound.TimePosition meaning the sound can be resumed using Sound:Resume().

The impact of the different Sound functions on Sound.Playing and Sound.TimePosition are shown below.

FunctionSound.PlayingSound.TimePosition
Sound:Play()TrueLast value set in Lua (default 0)
Sound:Pause()False-
Sound:Resume()True-
Sound:Stop()False0

Returns

void

Code Samples

Sound Functions

1-- create a sound
2local sound = Instance.new("Sound", game.Workspace)
3sound.SoundId = "rbxassetid://9120386436"
4
5if not sound.IsLoaded then
6 sound.Loaded:Wait()
7end
8
9-- listen for events
10sound.Played:Connect(function(_soundId)
11 print("Sound.Played event")
12end)
13
14sound.Paused:Connect(function(_soundId)
15 print("Sound.Paused event")
16end)
17
18sound.Resumed:Connect(function(_soundId)
19 print("Sound.Resumed event")
20end)
21
22sound.Stopped:Connect(function(_soundId)
23 print("Sound.Stopped event")
24end)
25
26sound:Play()
27print("play", sound.Playing, sound.TimePosition) -- play true 0
28
29task.wait(10)
30
31sound:Pause()
32print("pause", sound.Playing, sound.TimePosition) -- pause false 10
33
34task.wait(3)
35
36sound:Resume()
37print("play", sound.Playing, sound.TimePosition) -- play true 10
38
39task.wait(3)
40
41sound:Stop()
42print("stop", sound.Playing, sound.TimePosition) -- stop false 0
43
44task.wait(3)
45
46sound:Play()
47print("play", sound.Playing, sound.TimePosition) -- play true 0

Play

void

Plays the Sound. Sets Sound.TimePosition to the last value set by a Script (or 0 if it has not been set), and then sets Sound.Playing to true.

The impact of the different Sound functions on Sound.Playing and Sound.TimePosition are shown below.

FunctionSound.PlayingSound.TimePosition
Sound:Play()TrueLast value set in Lua (default 0)
Sound:Pause()False-
Sound:Resume()True-
Sound:Stop()False0

Returns

void

Code Samples

Sound Functions

1-- create a sound
2local sound = Instance.new("Sound", game.Workspace)
3sound.SoundId = "rbxassetid://9120386436"
4
5if not sound.IsLoaded then
6 sound.Loaded:Wait()
7end
8
9-- listen for events
10sound.Played:Connect(function(_soundId)
11 print("Sound.Played event")
12end)
13
14sound.Paused:Connect(function(_soundId)
15 print("Sound.Paused event")
16end)
17
18sound.Resumed:Connect(function(_soundId)
19 print("Sound.Resumed event")
20end)
21
22sound.Stopped:Connect(function(_soundId)
23 print("Sound.Stopped event")
24end)
25
26sound:Play()
27print("play", sound.Playing, sound.TimePosition) -- play true 0
28
29task.wait(10)
30
31sound:Pause()
32print("pause", sound.Playing, sound.TimePosition) -- pause false 10
33
34task.wait(3)
35
36sound:Resume()
37print("play", sound.Playing, sound.TimePosition) -- play true 10
38
39task.wait(3)
40
41sound:Stop()
42print("stop", sound.Playing, sound.TimePosition) -- stop false 0
43
44task.wait(3)
45
46sound:Play()
47print("play", sound.Playing, sound.TimePosition) -- play true 0

Resume

void

Resumes the Sound. Sets Sound.Playing to true. Does not alter Sound.TimePosition and thus can be used to resume the playback of a sound stopped using Sound:Pause().

The impact of the different sound functions on Sound.Playing and Sound.TimePosition are shown below.

FunctionSound.PlayingSound.TimePosition
Sound:Play()TrueLast value set in Lua (default 0)
Sound:Pause()False-
Sound:Resume()True-
Sound:Stop()False0

Returns

void

Code Samples

Sound Functions

1-- create a sound
2local sound = Instance.new("Sound", game.Workspace)
3sound.SoundId = "rbxassetid://9120386436"
4
5if not sound.IsLoaded then
6 sound.Loaded:Wait()
7end
8
9-- listen for events
10sound.Played:Connect(function(_soundId)
11 print("Sound.Played event")
12end)
13
14sound.Paused:Connect(function(_soundId)
15 print("Sound.Paused event")
16end)
17
18sound.Resumed:Connect(function(_soundId)
19 print("Sound.Resumed event")
20end)
21
22sound.Stopped:Connect(function(_soundId)
23 print("Sound.Stopped event")
24end)
25
26sound:Play()
27print("play", sound.Playing, sound.TimePosition) -- play true 0
28
29task.wait(10)
30
31sound:Pause()
32print("pause", sound.Playing, sound.TimePosition) -- pause false 10
33
34task.wait(3)
35
36sound:Resume()
37print("play", sound.Playing, sound.TimePosition) -- play true 10
38
39task.wait(3)
40
41sound:Stop()
42print("stop", sound.Playing, sound.TimePosition) -- stop false 0
43
44task.wait(3)
45
46sound:Play()
47print("play", sound.Playing, sound.TimePosition) -- play true 0

Stop

void

Stops the Sound. Sets Sound.Playing to false then sets Sound.TimePosition to 0.

The impact of the different sound functions on Sound.Playing and Sound.TimePosition are shown below.

FunctionSound.PlayingSound.TimePosition
Sound:Play()TrueLast value set in Lua (default 0)
Sound:Pause()False-
Sound:Resume()True-
Sound:Stop()False0

Returns

void

Code Samples

Sound Functions

1-- create a sound
2local sound = Instance.new("Sound", game.Workspace)
3sound.SoundId = "rbxassetid://9120386436"
4
5if not sound.IsLoaded then
6 sound.Loaded:Wait()
7end
8
9-- listen for events
10sound.Played:Connect(function(_soundId)
11 print("Sound.Played event")
12end)
13
14sound.Paused:Connect(function(_soundId)
15 print("Sound.Paused event")
16end)
17
18sound.Resumed:Connect(function(_soundId)
19 print("Sound.Resumed event")
20end)
21
22sound.Stopped:Connect(function(_soundId)
23 print("Sound.Stopped event")
24end)
25
26sound:Play()
27print("play", sound.Playing, sound.TimePosition) -- play true 0
28
29task.wait(10)
30
31sound:Pause()
32print("pause", sound.Playing, sound.TimePosition) -- pause false 10
33
34task.wait(3)
35
36sound:Resume()
37print("play", sound.Playing, sound.TimePosition) -- play true 10
38
39task.wait(3)
40
41sound:Stop()
42print("stop", sound.Playing, sound.TimePosition) -- stop false 0
43
44task.wait(3)
45
46sound:Play()
47print("play", sound.Playing, sound.TimePosition) -- play true 0