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 10 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
10 years ago
p=game.Workspace.Part   -- You only need to define this Once.

for i=1,150 do
    p.CFrame= p.CFrmae * CFrame.new(1,0,0)

    wait()
end

wait(1)


for i=150,1, -1 do
    p.CFrame= p.CFrmae * CFrame.new(-1,0,0) 
    wait()
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.

'i' == 3

p.Position = Vector3.new(  3,  0.9,  0)

e.g.2

'i' == 150

p.Position = Vector3.new( 150,  0.9,  0)
Ad
Log in to vote
1
Answered by
Gamenew09 180
10 years ago

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

for i=150,1, -1 do
    p.CFrame=CFrame.new(i,0.9,0) wait()
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.

Answer this question