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

Part Moves Diagonally?

I have a part moving, and for some reason it gradually moves diagonally. The part is anchored and cancollide true. This is a server script inside the part.

wait(3)
local part = script.Parent
while true do
wait(0.01)
part.CFrame = part.CFrame * CFrame.new(-Vector3.new(0,0,6))
end

2 answers

What are you trying to do with the script? If you're just trying to set it at a certain CFrame, you would want to do

part. CFrame = CFrame.new(x,y,z)

If you want to rotate it, I think you would want to do

part.CFrame = part.CFrame * Cframe.Angles(x,y,z).

I think when you're multiplying by CFrame.new(Vector3.new(x,y,z), you're moving the part from its current CFrame to the Vector3, a position in the Workspace, which is why it is gradually moving diagonally. Even if it is Anchored and cancollided, the script will still move it to its new position.

1 comment

0

Im trying to make it move gradually by adding a bit each time.

I'm winging it,

So when multiplying CFrames, the rotation properties of both can interfere with direction. To make the object move in a direction globally, multiply the position with the CFrame you want.

local part = script.Parent
while wait() do
	part.CFrame = CFrame.new(part.Position)*CFrame.new(0,0,-6)
end

Let me know if that works for you.

Good Luck!

If it did work, and I proved to be helpful, please don't forget to accept my answer.

2 comments

0

This caused this error: attempt to multiply a Vector3 with an incompatible value type or nil

0

Edited

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