The global scene object represents the current world scene.
Scenes allow you to section your world into different areas with separate player management.
Use cases:
- Access players in the current scene (
scene.players,scene.playerCount) - Listen for players joining or leaving the scene
- Get the scene's main camera (client-side)
- Instantiate scene prefabs (server-side)
- Access scene name and ID
Example usage:
Properties
An event triggered when a player joins the scene.
An event triggered when a player leaves the scene.
A unique identifier for this scene instance. This id indicates the order in which the scene was instantiated, not where it appears in the World Settings scene list.
You can use scene.name to get that identifier.
The main camera associated with the scene.
Methods
Returns
Instantiates a scene prefab at the specified position and rotation. The owner parameter determines which player "owns" the instantiated scene.
IMPORTANT: Server-side only.
Available on: Server only
--!Type(Server)
function self:ServerStart()
server.PlayerConnected:Connect(function(player)
-- Create a personal scene instance for the player
local personalScene = scene.Instantiate(
scenePrefab,
Vector3.new(0, 0, 0),
Vector3.new(0, 0, 0),
player
)
print("Created personal scene for " .. player.name)
-- Move player to their personal scene
server.MovePlayerToScene(player, personalScene)
end)
end
Returns
Updated 19 days ago