Vector3Value

Show Deprecated

A Vector3Value simply holds a Vector3 as a value. This value can be used for scripts to communicate, for objects to move to a preset location, etc.

Code Samples

Storing Vector2 inside Vector3Value

1local vector3Value = Instance.new("Vector3Value")
2
3-- Store a Vector2 in a Vector3
4local vector2 = Vector2.new(42, 70)
5vector3Value.Value = Vector3.new(vector2.X, vector2.Y, 0) -- The Z value is ignored
6
7-- Load a Vector2 from a Vector3
8vector2 = Vector2.new(vector3Value.Value.X, vector3Value.Value.Y)
9
10print(vector2)
Teleporter Part

1-- Paste me in a Script inside a Part
2local part = script.Parent
3
4local teleportPosition = part.TeleportPosition
5
6local function onTouch(otherPart)
7 -- First, find the HumanoidRootPart. If we can't find it, exit.
8 local hrp = otherPart.Parent:FindFirstChild("HumanoidRootPart")
9 if not hrp then
10 return
11 end
12
13 -- Now teleport by setting the CFrame to one created from
14 -- the stored TeleportPosition
15 hrp.CFrame = CFrame.new(teleportPosition.Value)
16end
17
18part.Touched:Connect(onTouch)

Summary

Properties

The stored Vector3.

Events


Fired whenever Vector3Value.Value is changed.

Methods

Properties

Events

Changed

Fired whenever the Vector3Value.Value of the Vector3Value is changed. It will run with the new value being stored in the argument object, instead of a string representing the property being changed.

This event, like other changed events, can be used to track when an Vector3Value changes and to track the different values that it may change to.

For instance, this may be useful in games that rely on Vector3Values to track positions in the game world.

Equivalent changed events exist for similar objects, such as NumberValue and StringValue, depending on what object type best suits the need.

Parameters

value: Vector3

The new value after the change.


Code Samples

How to Use Vector3Value.Changed

1local value = Instance.new("Vector3Value")
2value.Parent = workspace
3
4value.Changed:Connect(function(NewValue)
5 print(NewValue)
6end)
7
8value.Value = Vector3.new(10, 10, 10)

Methods