Skip to content

Api > SyncVar > Constructor


SyncVar(LuaBehaviour script, string Name, boolean global = false)⚓︎

Creates or links the existing synchronized variable. If the synchronized variable does not exist in the multiplayer sessions, it creates and returns a new variable, otherwise it returns the existing variable.

Parameters:⚓︎

Name Type Description
script LuaBehaviour The Script object. Can be accessed from LUA.script.
Name string Name of the variable.
global boolean Optional global value makes the synchronized variable accessible in every script if set to true. Otherwise, the synchronized variables scope is limited to the same script in same game object. Like local vs global events.

Usage⚓︎

---@type LuaBehaviour
local script;

---@type string
local Name;

---@type boolean
local global;


local syncvar = SyncVar(script, Name, global);

Extra Detail⚓︎

A synchronized variable created with a default value of nil. If a variable exists it’s value is synchronized with session.