Assigning Values to a specific Vector3 axis

I’ve looks on documentation and have been experimenting around for hours but I can’t seem to find how to assign onto a specific Vector3 axis.
e.g

local function plshelp(axis)
    local VecValue = Vector3.new(1,2,3)
    VecValue[axis] = 3
end

plshelp("Y")

it’s says a value cannot be assigned to it , I’m trying to make it so that you input an axis.

pls help me

  1. What is axis

  2. What is the Instance you are trying to get or assign?

For example

local vec = Vector3.new(1,2,3) -- 1= X axis, 2= Y axis and 3 = Z axis

print(vec.Z) -- this will return 3

I’m trying to change the value so for example

vec.Z = 10

but that errors

Vector3s are immutable. In other words, they don’t change. In order to set a specific axis value, you have to create a whole new Vector3. Don’t worry, Roblox is very optimized for this.

local vec = Vector3.new(1, 2, 3)
-- Change Z to 10:
vec = Vector3.new(vec.X, vec.Y, 10)
1 Like

Pretty much, yeah thats how that works