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

How do I make a script that moves a model forward then teleports it back?

Example : https://www.roblox.com/games/4617888640/Vibe-Train https://www.roblox.com/games/2091563160/Bus-Simulator

Basically the script goes

The scenery moves forward then gets teleported back rather seamlessly, either the scenery is incredibly long or the scenery gets teleported backward each time it hits a certain part.

2 comments

0

Please don't post requests. Show us what you have already tried, if you REALLY can't find anything and have searched for a long time, you should at least try to make your question's description better. If you are just looking for someone to make you a script then please do that in another platform/community.

0

I have tried for about eh, lets say 2 months?

1 answer

✓ Accepted answer

What your looking to use is the :MoveTo() function for models. you can find documentation on it here.

The moveto() function also moves it out of the way of anything, it won't clip with anything. If you want to move it without it moving out of the way, for example, a door moving into a part, you can find documentation on :SetPrimaryPartCFrame() here.

Now since your really vague with your question and not providing sample code of what you have tried, I can't really give you any code examples. Everything you need is on the wiki pages.

Edit:

I understand what you want now.

local originallocation = model.PrimaryPart.CFrame
for i = 1,100 do
	model:SetPrimaryPartCFrame(model.PrimaryPart.Position + Vector3.new(1,0,0)) -- Reduce the 1 for smoother movement. Increase the 100 for it to go longer.
	wait()
end
model:SetPrimaryPartCFrame(originallocation)

This code example below repeats it forever.

local originallocation = model.PrimaryPart.CFrame
while true do
	for i = 1,100 do
		model:SetPrimaryPartCFrame(model.PrimaryPart.Position + Vector3.new(1,0,0)) -- Reduce the 1 for smoother movement. Increase the 100 for it to go longer.
		wait()
	end
	model:SetPrimaryPartCFrame(originallocation)
end

17 comments

0

I've tried a tweenservice but it moves only 1 part and not the model, it also doesn't teleport backward instantly.

1

SetPrimaryPartCFrame() Moves things instantly. I do not know what you mean by "it also doesn't teleport backward instantly".

1

If you wish for the movement to be smooth, then do an while loop, adding onto the X or Z axis.

0

I script quite abit and I don't really understand what this means. Maybe becuase I don't do much CFraming

0

Okay, Ill try to provide a more detailed explanation. Basically it first goes to the part that I want it to smoothly (Basically a moveto or tween) then after it hits that part, it instantly is teleported back to the start point.

0

There is no complex CFrame involved. It's just like Vector3.new(vec3) except it moves models. Read the wiki articles i posted for pointers.

0

I don't understand any of that, I've been reading the articles for the last half a hour

0

nice answer, upvoted

0

It doesn't help me at all though.

0

If this doesn't help i don't know what will

0

probably will get some more advanced scripter to help out

0

You didn't have to insult me.

0

Im not insulting you, im just asking one of my more advanced scripter friends to help me out with this scirpt

0

About to try this, will provide you news

0

Works.

0

That was definitely very insulting, either you meant to or not

0

Late comment, apologies for that.

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