✓ Accepted answer
Two mistakes: To assign position to a part, you have to use a Vector3 or CFrame value. They x, y and z values of a Vector3 are read-only, meaning you can't manipulate them individually. Second, variables are references, they are not actually the instance. What you are doing is assigning b as the value of y, instead of assigning it as y itself. This means that instead, use b as a reference to the part, and manipulate it's position by obtaining it through the variable: b = workspace.Union
Here's the complete code:
b = workspace.Union
function a()
if b.Position.y == 13 then
repeat
wait(.5)
b.Position = Vector3.new(b.Position.x,b.Position.y + 1,b.Position.z)
until
b.Position.y == 27
else
repeat
wait(.5)
b.Position = Vector3.new(b.Position.x,b.Position.y - 1,b.Position.z)
until
b.Position.y == 13
end
end
function onClick()
a()
end
script.Parent.MouseButton1Up:connect(onClick)
1 comment
Also, you should use greater than/less than or equal to when using loops. That way, when using smaller increments, the code is much more likely to work.