Prefabs
spawns saved prefabs by name and translates between prefab names and their numeric ids
Methods
4 members Access: shared
- Exists
(name: string) -> boolean whether a prefab exists
Parameters
Name Type Description name string Prefab template name to check. returns boolean — - Id
(name: string) -> number lookup a prefab numeric id by name
Parameters
Name Type Description name string Prefab template name to look up the numeric identifier for. returns number — - Name
(id: number) -> string? lookup a prefab name by numeric id
Parameters
Name Type Description id number Numeric prefab identifier to look up the template name for. returns string? — - Spawn
(name: string) -> Instance? spawn a prefab by name
Parameters
Name Type Description name string Prefab template name to instantiate. returns Instance? —
Spawning Prefabs into the World
Lifecycle: Server
Check that a template exists before spawning it, then parent the copy into the world.
Luau
if game.Prefabs.Exists("Lantern") then local lamp = game.Prefabs.Spawn("Lantern") if lamp then lamp.Parent = game.World print("Spawned prefab:", lamp.Name) endend Output: Spawned prefab: Lantern