StudioService
StudioService provides access to configuration of Roblox Studio, allows importing files from the user's file system, and other miscellaneous information. It is intended to be used by Plugins in order to provide a consistent user experience.
- Plugins that allow the user to move objects may find GridSize, RotateIncrement and UseLocalSpace useful.
- Plugins that require the user to import files should use PromptImportFile or PromptImportFiles in order to receive File objects.
- Plugins that display icons of Instance classes can use GetClassIcon.
- Plugins that care about which script is currently being edited (if any) can read this from ActiveScript.
Summary
Properties
Reflects the LuaSourceContainer currently being edited (if any).
Determines the distance in studs by which Studio's drag and move tools move objects each tick.
Determines the degrees by which Studio's rotation tool will rotate selected objects each tick.
The locale currently in-use by Studio, e.g. en_US.
Determines whether Studio tools will use local space of an object or global space.
Methods
Properties
ActiveScript
ActiveScript refers to the LuaSourceContainer currently being edited by the user. If the user is not editing a script, this will be nil. Below is an example that shows how you can use this property to measure for how long a script was active.
local StudioService = game:GetService("StudioService")
local startTime = os.time()
local activeScript
local function onActiveScriptChanged()
local newActiveScript = StudioService.ActiveScript
if activeScript and newActiveScript ~= activeScript then
local deltaTime = os.time() - startTime
print(("You edited %s for %d:%2.d"):format(activeScript.Name, deltaTime // 60, deltaTime % 60))
end
startTime = os.time()
activeScript = newActiveScript
end
StudioService:GetPropertyChangedSignal("ActiveScript"):Connect(onActiveScriptChanged)
DraggerSolveConstraints
GridSize
GridSize determines the distance in studs by which Studio's drag and move tools move objects each tick. This is set in the user's Model tab under the Snap to Grid section.
RotateIncrement
RotateIncrement determines the angle in degrees by which Studio's rotation tool will rotate selected objects each tick. This is set in the user's Model tab under the Snap to Grid section.
Secrets
ShowConstraintDetails
ShowWeldDetails
StudioLocaleId
The StudioLocaleId property contains the locale currently in-use by Studio, e.g. en_US. It is useful when localizing plugins.
Below is a trivial example of localization based on the value returned by this function.
local locale = game:GetService("StudioService").StudioLocaleIdif locale == "en_US" thenprint("Howdy, ya'll")elseif locale == "en_GB" thenprint("'Ello, gov'na")elseif locale:sub(1, 2) == "en" thenprint("Hello")elseif locale == "fr_FR" thenprint("Bonjour")end
UseLocalSpace
UseLocalSpace determines whether the Studio movement/rotation tools will manipulate a part's CFrame using the local space of an object or global space. By default, this setting is toggled with CtrlL or ⌘L. Plugins can read from this property if they implement their own object movement tools.
Methods
GetClassIcon
GetClassIcon provides a dictionary that allows the display of a class' Explorer window icon, e.g. calling this function with "Part" returns property values that display the part icon from the Explorer window.
Below is a literal table representation of the value returned when this function is called with "Part".
{Image = "rbxasset://textures/ClassImages.png",ImageRectOffset = Vector2.new(16, 0),ImageRectSize = Vector2.new(16, 16)}
The utility function below may prove useful when displaying class icons:
local StudioService = game:GetService("StudioService")
local imageLabel = script.Parent
local function displayClassIcon(image, className)
for k, v in StudioService:GetClassIcon(className) do
image[k] = v -- Set property
end
end
displayClassIcon(imageLabel, "Part")
Parameters
Returns
GetUserId
Returns the Studio user's userId if they're logged in, otherwise returns 0.
Returns
Code Samples
-- Can only be used in a plugin
local StudioService = game:GetService("StudioService")
local Players = game:GetService("Players")
local loggedInUserId = StudioService:GetUserId()
local loggedInUserName = Players:GetNameFromUserIdAsync(loggedInUserId)
print("Hello,", loggedInUserName)
GizmoRaycast
Parameters
Returns
PromptImportFile
This function prompts the current Studio user to select one file, which will then be loaded as a File.
See also:
- StudioService:PromptImportFiles(), the same function but for loading a list of files instead of a single file
Parameters
A list of file types that the user is allowed to select. File types are formatted without a period. For example, {"jpg", "png"} would allow only a JPG or PNG file to be selected. If no filter is provided, the filter is nil and allows the user to select any file type.
Returns
PromptImportFiles
This function prompts the current Studio user to select one or more files, which will then be loaded as Files.
Throws an error if the fileTypeFilter was an empty list.
See also:
- StudioService:PromptImportFile(), the same function but for loading a single file instead of a list of files
Parameters
A list of file types that the user is allowed to select. File types are formatted without a period. For example, {"jpg", "png"} would allow only JPG and PNG files to be selected. If no filter is provided, the filter is nil and allows the user to select any file type.