Properties
ReverbType
|
The ambient sound environment preset used by |
float
|
The number of studs to be considered a meter by |
float
|
This property determines the degree to with a 3D |
bool
|
Sets whether |
float
|
Sets how fast 3D |
bool
|
Determines if an |
string
[ReadOnly]
[NotReplicated]
|
A read-only string representing the class this |
int
[Hidden]
[ReadOnly]
[NotReplicated]
[Deprecated]
|
The cost of saving the instance using data persistence. |
string
|
A non-unique identifier of the |
Instance
[NotReplicated]
|
Determines the hierarchical parent of the |
bool
[Hidden]
|
A deprecated property that used to protect |
bool
[Hidden]
[NotReplicated]
[Deprecated]
|
string
[ReadOnly]
[NotReplicated]
[Deprecated]
|
Functions
Tuple
|
GetListener returns |
void
|
Plays a |
void
|
Sets the listener for the |
void
|
This function destroys all of an |
Instance
|
Create a copy of an object and all its descendants, ignoring objects that are not |
void
|
Sets the |
Instance
|
Returns the first ancestor of the |
Instance
|
Returns the first ancestor of the |
Instance
|
Returns the first ancestor of the |
Instance
|
Returns the first child of the |
Instance
|
Returns the first child of the |
Instance
|
Returns the first child of the |
Instance
|
Variant
|
Returns the attribute which has been assigned to the given name |
RBXScriptSignal
|
Returns an event that fires when the given attribute changes |
Dictionary
|
Returns a dictionary of string → variant pairs for each of the |
Objects
|
Returns an array containing all of the |
string
[NotBrowsable]
|
Returns a coded string of the |
Array
[CustomLuaState]
|
Returns an array containing all of the descendants of the instance |
string
|
Returns a string describing the |
RBXScriptSignal
|
Get an event that fires when a given property of an object changes. |
bool
[CustomLuaState]
|
Returns true if an |
bool
|
Returns true if an |
bool
|
Returns true if an |
void
[Deprecated]
|
Sets the object’s Parent to nil, and does the same for all its descendants. |
void
|
Sets the attribute with the given name to the given value |
Instance
[CustomLuaState]
[CanYield]
|
Returns the child of the |
Objects
[Deprecated]
|
Returns an array of the object’s children. |
Instance
[Deprecated]
|
void
[Deprecated]
|
Instance
[Deprecated]
|
Objects
[Deprecated]
|
bool
[Deprecated]
[CustomLuaState]
|
bool
[Deprecated]
|
void
[Deprecated]
|
Events
RBXScriptSignal
|
Fires when the |
RBXScriptSignal
|
Fires whenever an attribute is changed on the |
RBXScriptSignal
|
Fired immediately after a property of an object changes. |
RBXScriptSignal
|
Fires when an object is parented to this |
RBXScriptSignal
|
Fires when a child is removed from this |
RBXScriptSignal
|
Fires when a descendant is added to the |
RBXScriptSignal
|
Fires immediately before a descendant of the |
RBXScriptSignal
[Deprecated]
|
Code Samples
Dynamic Reverb System
The code in this sample, when ran from a LocalScript
, will change the SoundService/AmbientReverb
property of SoundService
when the player is inside a BasePart
tagged using CollectionService
.
To add or remove tags and reverb types, change the entries in the ‘reverbTags’ table.
local Players = game:GetService("Players") local CollectionService = game:GetService("CollectionService") local SoundService = game:GetService("SoundService") local localPlayer = Players.LocalPlayer -- define tags local reverbTags = { ["reverb_Cave"] = Enum.ReverbType.Cave } -- collect parts and group them by tag local parts = {} for reverbTag, reverbType in pairs(reverbTags) do for _, part in pairs(CollectionService:GetTagged(reverbTag)) do parts[part] = reverbType end end -- function to check if a position is within a part's extents local function positionInPart(part, position) local extents = part.Size / 2 local offset = part.CFrame:pointToObjectSpace(position) return offset.x < extents.x and offset.y < extents.y and offset.z < extents.z end local reverbType = SoundService.AmbientReverb while true do wait() if not localPlayer then return end local character = localPlayer.Character -- default to no reverb local newReverbType = Enum.ReverbType.NoReverb if character and character.PrimaryPart then local position = character.PrimaryPart.Position -- go through all the indexed parts for part, type in pairs(parts) do -- see if the character is within them if positionInPart(part, position) then -- if so, pick that reverb type newReverbType = type break end end end -- set the reverb type if it has changed if newReverbType ~= reverbType then SoundService.AmbientReverb = newReverbType reverbType = newReverbType end end
Play Local Sound
This sample creates and plays a sound locally when a button in a custom Studio plugin is pressed.
local SoundService = game:GetService("SoundService") -- Create custom plugin button local toolbar = plugin:CreateToolbar("Empty Script Adder") local newScriptButton = toolbar:CreateButton("Add Script", "Create an empty Script", "rbxassetid://1507949215") local function playLocalSound(soundId) -- Create a sound local sound = Instance.new("Sound") sound.SoundId = soundId -- Play the sound locally SoundService:PlayLocalSound(sound) -- Once the sound has finished, destroy it sound.Ended:Wait() sound:Destroy() end local function onNewScriptButtonClicked() -- Create new empty script local newScript = Instance.new("Script") newScript.Source = "" newScript.Parent = game:GetService("ServerScriptService") -- Call function to play local sound playLocalSound("") -- Insert audio asset ID here end -- Connect plugin button to action function newScriptButton.Click:Connect(onNewScriptButtonClicked)