Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How fix this error: "Y cannot be assigned to"? Y position of object not changing.

Asked by 4 years ago

And so, since I'm not a lua professional, I don't know how to fix the error. If the player's Y position is greater than the rocket's Y position, then the rocket's Y position is increased by 0.1. And if less than the opposite. And when the script starts working, this error appears "Y cannot be assigned to"

This is my code: (thanks in advance)

while 1==1 do
    wait()
    playerY = _G.evastefan.Torso.Position.Y
    if rocket.Position.Y < playerY then
        rocket.Position.Y = rocket.Position.Y+0.1
    else
        rocket.Position.Y = rocket.Position.Y-0.1
    end

end
0
Y is a read-only property of Vector3 values, just like X and Z DeceptiveCaster 3761 — 4y
0
I will know, thank you!) evastefan 2 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

You can't assign properties in a Vector3.

To change these values, you'll need to set the Position to a new Vector3, after setting it to move where you want it to.

while 1==1 do
    wait()
    playerY = _G.evastefan.Torso.Position.Y
    if rocket.Position.Y < playerY then
        rocket.Position = rocket.Position + Vector3.new(0, 0.1, 0) --Add the new vector Vector3.new(0, 0.1, 0) to our rocket so we move it up
    else
        rocket.Position = rocket.Position - Vector3.new(0, 0.1, 0) --And vise versa for moving it down
    end

end
0
ok, thanks!) evastefan 2 — 4y
Ad

Answer this question