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

whats wrong with my moving script? ~solved~

Asked by 11 years ago

im trying to make a part that goes to one side then moves back to where it came from and stops there, heres my script. ~~~~~~~~~~~~~~~~~ --Made by bubbaman73!

p=game.Workspace.Part

for i=150,1, -1 do p.CFrame=CFrame.new(i,0.9,0) wait() end

wait(1)

p=game.Workspace.Part

for i=150,1, -1 do p.CFrame=CFrame.new(i,0.9,0) wait() end

~~~~~~~~~~~~~~~~~ Its now looping but it wont go back and forth stil

2 answers

Log in to vote
1
Answered by
hiccup111 231 Moderation Voter
11 years ago
01p=game.Workspace.Part   -- You only need to define this Once.
02 
03for i=1,150 do
04    p.CFrame= p.CFrmae * CFrame.new(1,0,0)
05 
06    wait()
07end
08 
09wait(1)
10 
11 
12for i=150,1, -1 do
13    p.CFrame= p.CFrmae * CFrame.new(-1,0,0)
14    wait()
15end

(line 4) This will take the current position of 'p', then push it on the x.Axis by 1

Before, you was asking it to move to a specific position.

e.g.

1'i' == 3
2 
3p.Position = Vector3.new(  30.90)

e.g.2

1'i' == 150
2 
3p.Position = Vector3.new( 1500.90)
Ad
Log in to vote
1
Answered by
Gamenew09 180
11 years ago

You need to add the following to the second for loop:

1for i=150,1, -1 do
2    p.CFrame=CFrame.new(i,0.9,0) wait()
3end

You need to subtract by 1 otherwise it will go from 150 and add more.

If I helped please accept me as an answer, which should be on the right of this answer, and vote me up! If I got anything wrong I am sorry.

P.S. Please use the code block, just click the Lua button on top of the writing box while editing.

Answer this question