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

Could a function with parameters help to not repeat this code?

This code is working just fine but I am wondering it there could be a function that has parameter or arguments to make this have less lines.

NOTICE: I'm pretty much repeating the code but some things a different.

while true do
	local canFade = true
	for i = 0,1,.001 do
		cam.CFrame = cam1.CFrame:lerp(cam2.CFrame,i)
		game:GetService('RunService').RenderStepped:wait()
		if i >= .98 and canFade then
			canFade = false
			fade(playerGui:FindFirstChild('Main').FadeBackground)
		end
	end
	
	local canFade = true
	for i = 0,1,.001 do
		cam.CFrame = cam3.CFrame:lerp(cam4.CFrame,i)
		game:GetService('RunService').RenderStepped:wait()
		if i >= .98 and canFade then
			canFade = false
			fade(playerGui:FindFirstChild('Main').FadeBackground)
		end
	end
	
	local canFade = true
	for i = 0,1,.001 do
		cam.CFrame = cam5.CFrame:lerp(cam6.CFrame,i)
		game:GetService('RunService').RenderStepped:wait()
		print'c'
		if i >= .98 and canFade then
			canFade = false
			fade(playerGui:FindFirstChild('Main').FadeBackground)
		end
	end
	
	local canFade = true
	for i = 0,1,.001 do
		cam.CFrame = cam7.CFrame:lerp(cam8.CFrame,i)
		game:GetService('RunService').RenderStepped:wait()
		if i >= .98 and canFade then
			canFade = false
			fade(playerGui:FindFirstChild('Main').FadeBackground)
		end
	end
	
	local canFade = true
	for i = 0,1,.001 do
		cam.CFrame = cam9.CFrame:lerp(cam10.CFrame,i)
		game:GetService('RunService').RenderStepped:wait()
		if i >= .98 and canFade then
			canFade = false
			fade(playerGui:FindFirstChild('Main').FadeBackground)
		end
	end
end

3 comments

2

yes...

0

Ok, I will try then.

0

Yes, b/c you wont have to keep rewriting over-and-over. That's one of the powers of lua! >>:D

1 answer

Oh my yes. Make a parameter like cam and just switch out cam10,CFrame to cam so every time you call the function you can just write functionName(cam4.CFrame) or whatever 'cam' you plan to change. Hope I helped! ;)

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