World¶
System · World · server and client scripts
World is the top of the place's tree of parts and entities. It also runs queries over scene entities and schedules per-frame systems. The server and each client have their own world, and a call acts on the world of the side that makes it.
A part at the top of the place has World as its Parent, and part.Parent = World moves a part there. Find an entity at the top of the place with World.Find(path), list children with World.Children() or World.Descendants(), and wait for an entity with World.WaitFor(path, seconds).
Children¶
Children returns an array of every top-level entity in the world.
Descendants¶
Descendants returns an array of every entity in the world, top level first.
Find¶
Find resolves a child name or slash-separated path from the top of the world and returns the matching entity, or nil.
FindDescendant¶
FindDescendant searches every level of the world for the first entity with the given name and returns it, or nil.
Example
WaitFor¶
WaitFor waits until a top-level entity or path exists in the world, or until seconds seconds pass, returning the entity or nil.
Example
On¶
On connects a handler to a singleton component signal and returns a Connection.
Example
Once¶
Once connects a one-shot handler to a singleton component signal and returns a Connection.
Example
Wait¶
Wait yields until a singleton component signal fires or seconds pass, returning true and the signal arguments on fire or false on timeout.
Override¶
Override sets a client-only override on a singleton presentation component or field without changing replicated state.
ClearOverride¶
ClearOverride removes a local client presentation override on a singleton presentation component or field.
GetOverride¶
GetOverride returns the active local client presentation override value on a singleton component or field, or nil if no override is active.
Gravity¶
Gravity is the world-space acceleration vector, in units per second squared, that pulls every unanchored body. Negative Y pulls down. A server write replicates to clients. Particles with ParticleGravity.Scale 1 fall at minus Gravity.Y / 20 units per second squared.
Default Vector3.new(0, -196.2, 0)
Example
Clock¶
Clock: { read Tick: number, read ServerTime: number, read TickRate: number, read SessionTime: number }
Clock exposes the simulation tick counter (Tick), fixed tick rate in Hz (TickRate), synchronized server clock in seconds (ServerTime), and local session uptime in seconds (SessionTime).
Sun¶
Sun is the world's directional sunlight singleton. See Sun for Azimuth, Elevation, Tint, and Intensity.
Ambient¶
Ambient is the world's ambient lighting singleton. See Ambient for Source, Tint, Contribution, and Intensity.
Clouds¶
Clouds is the world's volumetric cloud layer singleton. See Clouds for cloud coverage, density, height, wind, and shading settings.
Fog¶
Fog is the world's distance fog singleton. See Fog for Color, Mode, Density, Start, and End.
Exposure¶
Exposure is the world's automatic exposure singleton. See Exposure for MinEV and MaxEV.
Flare¶
Flare is the world's sun lens flare singleton. See Flare for Intensity, Scale, Tint, Ghost, and Rays.
PlayerSpawner¶
PlayerSpawner is the world singleton that spawns and respawns player characters. See PlayerSpawner for CharacterPrefab, RespawnDelay, AutoSpawn, and Spawn.
DefineComponent¶
DefineComponent declares a component and returns its Component handle. Each entry in fields is a default value whose Luau type sets the field type or a Field descriptor: a number defines an f64 field, a boolean a bool, a string a string, a vector (Vector3) a vec3, a Vector2 a vec2, a Color a color, a Rotation a rotation, and a UIVector a UI coordinate. Use Field.Entity, Field.List, Field.Enum, and Field.Optional for entity references, arrays, string enums, and optional values.
A component with no fields is a tag. Reading entity.Enemy returns true while the tag is attached and nil otherwise. A server script can name a tag after DefineComponent declares it or the place file defines it; a client script can name any tag replicated from the server.
options accepts a ComponentOptions table with Scope ("Replicated", "Server", or "Client"), Saved, Singleton, Signals, PlayerList, Exclusive, OnDeleteTarget, and Hints. Each entry in Signals is an array of Field.Arg(name, default) descriptors that creates a DeclaredSignal member on the returned component handle.
Example
-- Server script.
local Stamina = World.DefineComponent("Stamina", {
Current = 100,
Max = 100,
Tint = Color.White,
}, {
Scope = "Replicated",
Signals = {
Drained = { Field.Arg("amount", 0) },
},
})
local entity = World.Spawn({})
entity:Add(Stamina)
local drained: DeclaredSignal<number> = (Stamina :: any).Drained
drained:Connect(function(e: Entity, amount: number)
print(e.Name, amount)
end)
drained:Fire(entity, 25)
local Enemy = World.DefineComponent("Enemy")
entity:Add(Enemy)
Queries¶
Pair¶
Pair makes a relationship pair for World.Query, World.Spawn, Entity:Add, and Entity:Has. The relation is "ChildOf", "Tag" or "WornBy", and the target "*" matches any target.
Example
Query¶
Query builds a cached query over scene entities that have every given component and pair. Column describes the columns returned by query:Column(component).
Example
Errors (1)
| Error | When |
|---|---|
World.Query: live query cap reached (256); queries must be created at script load, not per tick |
Create queries when the script loads, not in a loop or a per-frame callback. |
Spawn¶
Spawn¶
Spawn creates an entity at the top of the place with the given components and tag pairs.
Example
Errors (1)
| Error | When |
|---|---|
World.Spawn: cannot mix 3D and UI components ('<name>') |
The arguments name both a 3D and a UI component. |