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

How Do I Get A Brick To Move Back And Forth Constantly?[UnSolved]


while true do
wait()
for i = 1, 5 do
wait(3)	
	game.workspace.Mover1.Position = CFrame.new(game.workspace.Mover1.Position + Vector3.new(0,0,1))
	wait(2)
	game.workspace.Mover1.Position = CFrame.new(game.workspace.Mover1.Position + Vector3.new(0,0,-1))
end
end

I'm trying to make a brick go back and forth. I used this script and so far it says It's a bad argument. How could I fix this? Or at least help me out on making a brick move back and forth. And do I need the "While True Do" loop?

2 answers

✓ Accepted answer

'Position' is a Vector3 property, not a CFrame one. You could use 'CFrame' in place of 'Position' to avoid the built-in collision check for 'Vector3.'

I wouldn't put them in the same 'for' loop, but that depends what you want the loop to do.

If you want the script to have Mover1 move about 5 units, waits for 2 seconds, then move 5 units back, then consider coding the script this way:

while true do
	wait(3)
	for i = 1, 5 do
		game.Workspace.Mover1.CFrame = game.Workspace.Mover1.CFrame * CFrame.new(0,0,1)
	end		-- This gets the CFrame of Mover1, then adds 1 unit to the z-axis. This will be done 5 times. In total, it would be displaced 5 units away from the initial point.
	wait(2)
	for i = 1, 5 do
		game.Workspace.Mover1.CFrame = game.Workspace.Mover1.CFrame * CFrame.new(0,0,-1)
	end
end

Otherwise, if you want the script to wait for 3 seconds, have Mover1 to move 1 unit, wait for 2 seconds, then move 1 unit back five times, then consider coding the script this way:

while true do
	wait(3)
	for i = 1, 5 do
		game.Workspace.Mover1.CFrame = game.Workspace.Mover1.CFrame * CFrame.new(0,0,1)
	wait(2)
		game.Workspace.Mover1.CFrame = game.Workspace.Mover1.CFrame * CFrame.new(0,0,-1)
	end
end

I'm pretty sure Position is Vector3, not CFrame

2 comments

0

That helped but now my brick moves all the way to the center of my game.

0

thats because you set the position to the coordinates 0,0,1. My way on finding coordinates in your world is to get a 1x1 part, then place it where you want it, and the position property has the 3 numbers, which are Vector3

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