0

# I need help with this Vector3 Script?

So part of this Toaster I'm making, I want the switch to go down. (The switch's size is 0.2, 0.2, 0.2)

I made 2 scripts, one with a specific Vector3 Value to put it at The other one with subtracting then adding Vector3

Both of them made the switch go up above the toaster, and not down.

Here are the scripts: (I'm only putting the Vector3 part of it)

The one with adding or subtracting

script.Parent.Position = script.Parent.Position - Vector3.new(0,0.5,0)
wait(0.7)
script.Parent.Position = script.Parent.Position + Vector3.new(0,0.5,0)


The one with specific Vector3

script.Parent.Position = Vector3.new(51.876, 6.59, 24.58)
wait(0.7)
script.Parent.Position = Vector3.new(51.876, 6.94, 24.58)


1
Perci1 4988
7 years ago

Subtracting from the y coordinate (or adding negatives) is your best bet.

Your problem is likely that the part is either slightly inside of another part or there's some parts in the way.

To fix this, use CFrame, for it will ignore other parts in the way.

script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, -0.5, 0)


You may have noticed the *, signifying multiplication. This can be very confusing, but with CFrame multiplication works the same as adding (even though we are technically not adding).

If you just desperately want to use the + sign, you can add a Vector3 to a CFrame, i.e.

script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0, -0.5, 0)

0
Thank you! It worked! SpazzMan502 133 — 7y