Codectionary / Developer documentation / Luau

ObjectValue references

Store a reference to another Roblox instance.

Why use ObjectValue?

ObjectValue is a container whose Value refers to an Instance or nil. It can link two objects in Studio, but it is not a substitute for server-side permission checks.

Try it in Roblox Studio

Create a BasePart named Target in Workspace. Put this Script in ServerScriptService and inspect the ObjectValue child in Explorer.

Syntax

reference.Value = target

Examples

ObjectValue references

Attach a target reference to a part.

local target = workspace:WaitForChild("Target")
local reference = Instance.new("ObjectValue")
reference.Name = "SelectedTarget"
reference.Value = target
reference.Parent = workspace
print(reference.Value:GetFullName())
  1. Value holds a reference to the Target instance, not its name as text.
  2. Another script can read reference.Value to obtain the same object while it exists.
  3. If the target is destroyed, code must still handle a missing or unusable reference.

Best practices

  • Check a stored reference before acting on it.
  • Do not trust client-controlled references for authority on the server.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

Specifications & further reading