Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

Y is a read-only property of Vector3 values, just like X and Z

0

I will know, thank you!)

1 answer

✓ Accepted answer

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

1 comment

0

ok, thanks!)

This discussion is preserved as it was. New answers, comments, and votes are closed.