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

Any other way to move parts with cframe using for i loop?

This is the current script i'm using.

while true do
	for i=1,100 do
		script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,-0.1,0)
		wait()
	end
	for i=1,100 do
		script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0.1,0)
		wait()
	end
end

But, how do i move the part to exact location like x32, y25, z56, i heard there is a thing called "wait until' but i don't really know how to use it, any one knows how to do this?

1 comment

0

repeat loop

2 answers

✓ Accepted answer

If you want to move it to specific coordinates, you'd have to use the CFrame:lerp() method.

This can be done like the following:

local coords = CFrame.new(x,y,z) -- Coordinates
local current = CFrame.new();
local Part = script.Parent;

for x=0,1,.01 do
	Part.CFrame = current:lerp(coords, x)
	wait()
end

This smoothly move the part to the location. Note that you should have anchored enabled.

1 comment

0

i didn't know there was such a thing as cframe:lerp() but it works! thanks :D

Yes, you can move parts with cframe using for i loop and here is an script

while true do
    for i=1,100 do
        script.Parent.CFrame = CFrame.new(script.Parent.Position + Vector3.new(0,-0.1,0)) --on this line game adding -0.1 to the current position
        wait()
    end
	for i=1,100 do
        script.Parent.CFrame = CFrame.new(script.Parent.Position + Vector3.new(0,0.1,0)) 
        wait()
    end
end

And here is your request

while true do
	if script.Parent.Position.Y >= 5 then
		break --Closing cycle when y of the position reaches 5
	end
    for i=1,100 do
        script.Parent.CFrame = CFrame.new(script.Parent.Position + Vector3.new(0,0.1,0)) 
        wait()
    end
end

print("end")

1 comment

0

Yes, but how do i move it to a specific coordination (x,y,z) ?

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