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
01 | p = game.Workspace.Part -- You only need to define this Once. |
02 |
03 | for i = 1 , 150 do |
04 | p.CFrame = p.CFrmae * CFrame.new( 1 , 0 , 0 ) |
05 |
06 | wait() |
07 | end |
08 |
09 | wait( 1 ) |
10 |
11 |
12 | for i = 150 , 1 , - 1 do |
13 | p.CFrame = p.CFrmae * CFrame.new(- 1 , 0 , 0 ) |
14 | wait() |
15 | end |
(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 |
3 | p.Position = Vector 3. new( 3 , 0.9 , 0 ) |
e.g.2
1 | 'i' = = 150 |
2 |
3 | p.Position = Vector 3. new( 150 , 0.9 , 0 ) |
You need to add the following to the second for loop:
1 | for i = 150 , 1 , - 1 do |
2 | p.CFrame = CFrame.new(i, 0.9 , 0 ) wait() |
3 | end |
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.