Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
608b 4
4 years ago
Edited 4 years ago

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.

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. Torren_Mr 334 — 4y
0
I have tried for about eh, lets say 2 months? 608b 4 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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
0
I've tried a tweenservice but it moves only 1 part and not the model, it also doesn't teleport backward instantly. 608b 4 — 4y
1
SetPrimaryPartCFrame() Moves things instantly. I do not know what you mean by "it also doesn't teleport backward instantly". RunKittenzRComin 170 — 4y
1
If you wish for the movement to be smooth, then do an while loop, adding onto the X or Z axis. RunKittenzRComin 170 — 4y
0
I script quite abit and I don't really understand what this means. Maybe becuase I don't do much CFraming 608b 4 — 4y
View all comments (13 more)
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. 608b 4 — 4y
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. RunKittenzRComin 170 — 4y
0
I don't understand any of that, I've been reading the articles for the last half a hour 608b 4 — 4y
0
nice answer, upvoted EmbeddedHorror 299 — 4y
0
It doesn't help me at all though. 608b 4 — 4y
0
If this doesn't help i don't know what will RunKittenzRComin 170 — 4y
0
probably will get some more advanced scripter to help out 608b 4 — 4y
0
You didn't have to insult me. RunKittenzRComin 170 — 4y
0
Im not insulting you, im just asking one of my more advanced scripter friends to help me out with this scirpt 608b 4 — 4y
0
About to try this, will provide you news 608b 4 — 4y
0
Works. 608b 4 — 4y
0
That was definitely very insulting, either you meant to or not RunKittenzRComin 170 — 4y
0
Late comment, apologies for that. RunKittenzRComin 170 — 4y
Ad

Answer this question