#Why is declaring a variable confusing?

1 messages · Page 1 of 1 (latest)

ornate iris
#

Why does this work
local Bloom = game.Workspace.Block
Bloom.Position = Vector3.new(0,1,0)

Why does this not work
local Bloom = game.Workspace.Block.Position
Bloom = Vector3.new(0, 1, 0)

or even(doesnt work either)
local Bloom = game.Workspace.Block.Position = Vector3.new(0,1,0)

Aren't these the same thing?
I'm just learning and practicing Luau and my first obstacle is not even being able to understand how to move the position of Block.

ornate iris
worn stump
#

weird

gritty python
# ornate iris Why does this work local Bloom = game.Workspace.Block Bloom.Position = Vector3.n...

You assign a variable with the assignment operator: =

x = y

This is the sole method of variable initialization and modification in Luau. This immediately invalidates your third idea. As for your second, you're attempting to create a reference to a property. This is not a valid operation in Luau, so your variable will simply store the value currently at that property. Assigning to the variable overwrites the variable, not the property

ornate iris
gritty python
#

A perfect example is C/C++

gritty python
#
10
10
void mason
gritty python
#

You're just changing one from the value 1 to a reference to game.Workspace.Part

void mason
#

so hes trying to change the block's position to vector3.new(0,1,0)

#

if you reference the block.position = vector3.new() it would directly get the block and get its position

#

honestly im not sure why lua is like this but it seems u need to reference the part directly and get the position from it
u cant get the position and change it because for some reason you have to reference the part and use the position from there
thats odd but ig it works

gritty python
#
x = y = z

Is a valid feature in some languages

#

For example, Python:

x = 1
y = 2
z = 3

x = y = z

print(x, y, z)
3 3 3
#

This essentially translates to y = z, then x = y

gritty python
void mason
gritty python
#

You would require a reference to the memory address, which is unsafe

#

Roblox intends to deliver a lightweight scripting experience to its developers

ornate iris
sturdy falconBOT
#

studio** You are now Level 2! **studio

ornate iris
worn stump