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

whats wrong with my moving script? ~solved~

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

✓ Accepted answer
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)

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.

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