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

(very easy) Is there any way to make this script more efficient (fewer lines)?

heres the script:

local CFrameTester = script.Parent


 script.Parent.Parent.Tester1.Touched:Connect(function()
		
		wait(2)
	
	script.Parent.Position = Vector3.new(-26.59, 3.07, 377.94)
	wait(0.2)
	script.Parent.Position = Vector3.new(-26.59, 3.07, 376.94)
	wait(0.2)
	script.Parent.Position = Vector3.new(-26.59, 3.07, 375.94)
	wait(2)
	script.Parent.Position = Vector3.new(-26.59, 3.07, 374.94)
	wait(0.2)
	script.Parent.Position = Vector3.new(-26.59, 3.07, 373.94)
	wait(0.2)
	script.Parent.Position = Vector3.new(-26.59, 3.07, 372.94)
	wait(2)
	
	end)
		

1 comment

0

Just add a for loop loop.

3 answers

you could use something that's useful for doing repeated stuff

ex:

local AmountOfTimes = 3

for i=1, AmountOfTimes do
	-- this will repeat whatever is inside this code as many as wanted times.
end;

2 comments

0

Why is there a ";" at the end at line 5?

0

thats a javascript habit sorry xD it means nothing other than end of line

You should use a while true do loop so if would loop infinitely.

local CFrameTester = script.Parent


 script.Parent.Parent.Tester1.Touched:Connect(function()

       while true do wait(2)
	script.Parent.Position = Vector3.new(-26.59, 3.07, 375.94)
end
    end)

Hello snipperdiaper,

local CFrameTester = script.Parent
script.Parent.Parent.Tester1.Touched:Connect(function()
	local pos = script.Parent.Position
	local z = 378.94
	local vec3 = Vector3.new(-26,59, 3.07, z)
	wait(2)
	for i = 1, 2, 1 do
		for i = 0, 2, 1 do
			z = z - 1
			pos = vec3
			wait(0.2)
		end
		z = z - 1
		pos = vec3
		wait(2)
	end
end)

Hope I helped!

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