Moving part rotation

Hello, When I try the script, the part is backwards while going forward how do I get it to rotate it so that it will face on the forward direction like its suppose to do?

    workspace.tm.PrimaryPart = workspace.tm.tp

while true do
	for i=1, 250 do
		wait()

		workspace.tm:SetPrimaryPartCFrame(CFrame.new(workspace.tm.PrimaryPart.Position + Vector3.new(0,0,-6)))
		
	end
	wait(5)

	for i=1,100 do
		wait()

		workspace.tm.tp.CFrame = CFrame.new(-181.1, 0.5, 765.5)
		
	end
	wait(.2)
	end
1 Like

Try Putting the exact OPPOSITE cordinates. instead of -181.1, 0.5, 765.5, do 181.1, -0.5, -765.5

thats for positioning the part back to where it was originally, i’m trying to get the part to move where its going while its moving

Well, then I don’t really understand the problem. Sorry but I don’t know how to help you.

i’ve tried using CFrame.Orientation but it just goes somewhere and all the other cframe method

Do you mean your part is facing in the wrong direction?
If I understand you right then rotating part for 180deg using CFrame.Angles would be the solution.

workspace.tm:SetPrimaryPartCFrame(CFrame.new(workspace.tm.PrimaryPart.Position + Vector3.new(0,0,-6)) * CFrame.Angles(0,math.pi,0))

Hello,
First of all, I would like to say that your explanation of the problem is quite confusing. Some people may not understand the problem if they do not take a second glance at it.
Secondly, to fix your issue, we need to have a better grasp/understanding of the problem, so I decided to do some indenting fixes to have a better look at the issue.

My logic: Indenting anything that is longer than hellohowareyoudoing or more is shortened with a new line.

workspace.tm.PrimaryPart = workspace.tm.tp
while true do
	for i = 1, 250 do
		wait()
		workspace.tm:SetPrimaryPartCFrame(
			CFrame.new(
				workspace.tm.PrimaryPart.Position +
				Vector3.new(0,0,-6)
			)
		)
	end
	
	wait(5)

	for i = 1, 100 do
		wait()
		workspace.tm.tp.CFrame = CFrame.new(
			-181.1,
			0.5,
			765.5
		)
	end
	wait(.2)
end

With better formatting, I can start to see a few issues with your code.

  1. At line 15+, what’s with setting the CFrame of the part to a constant position 100 times? This would only lag the server for no necessary reason.
  2. At line 3-11, You are resetting the orientation of the part in your CFrame.new() block.
    This is unnecessary.
    Another issue I saw is that you are adding to the Primary part’s position with a Vector3, which is probably the issue you are currently facing. This is a simple fix, as so:
for i = 1, 250 do
	wait()
	workspace.tm:SetPrimaryPartCFrame(
		workspace.tm:GetPrimaryPartCFrame() *
        CFrame.new(0, 0, -6)
	)
end
  1. At line 1, you are setting the PrimaryPart of the object. This is unnecessary, since you are able to set it using ROBLOX’s properties menu, as such:
    image
    image
    Simple fix without reinventing the wheel.

With these fixes in mind, you should have your problem solved.
Some other tips:

Due to floating point and other stuff with the for loop, I’d suggest storing the PrimaryPart’s CFrame before hand, so you can easily multiply it and revert back to it after your loop.
Something like this:

local Model = workspace:WaitForChild("tm") -- I like using WaitForChild, you don't exactly *need* to.
local OriginalCFrame = Model:GetPrimaryPartCFrame()

while true do
	for i = 1, 250 do
		wait()
		Model:SetPrimaryPartCFrame(
			OriginalCFrame *
			CFrame.new(0, 0, -6 * i)
		)
	end
	
	wait(5)
	Model:SetPrimaryPartCFrame(OriginalCFrame)
	
	wait(.2)
end

This way, there’s not much of an issue with floating point, and you aren’t setting some extremely precise position for it to go to (which will be weird if you move the model to a different position).
If there’s any issues with my solution, just reply to my comment. :wink:

1 Like

Taking another glance at your code, I’m assuming you’re trying to revert back to the original position in 100 steps. This is an easy fix, by just counting backwards using the step argument in a for loop.

for i = 100, 1, -1 do
	wait()
	Model:SetPrimaryPartCFrame(
		OriginalCFrame *
		CFrame.new(0, 0, -6 * i)
	)
end
Model:SetPrimaryPartCFrame(OriginalCFrame)

As a backup: If I completely misunderstood your question, and it was just about it not facing the right way, consider rotating the model:
GHCtlgQhPY
(Note, how much you should rotate it depends on what direction the model travels in.)

1 Like

thank you it was able to face the direction it was going :+1: :+1: :smiley:

1 Like