Here, I am trying to make spoilers retract and extend, but it throws an error. I have two separate scripts which retracts and extends them. I am wondering is it because that the part in the script which assigns variables is too long?

Retracting

local rt4 = script.Parent.Parent.FG1:WaitForChild("RT_FOUR",100).Motor
local rt3 = script.Parent.Parent.FG1:WaitForChild("RT_THREE",100).Motor
local rt2 = script.Parent.Parent.FG1:WaitForChild("RT_TWO",100).Motor
local rt1 = script.Parent.Parent.FG1:WaitForChild("RT_ONE",100).Motor
local s1 = script.Parent.Parent.FG1:WaitForChild("S_ONE",100).Motor
local s2 = script.Parent.Parent.FG1:WaitForChild("S_TWO",100).Motor
local s3 = script.Parent.Parent.FG1:WaitForChild("S_THREE",100).Motor
local s4 = script.Parent.Parent.FG1:WaitForChild("S_FOUR",100).Motor
local s5 = script.Parent.Parent.FG1:WaitForChild("S_FIVE",100).Motor
local s6 = script.Parent.Parent.FG1:WaitForChild("S_SIX",100).Motor
local s7 = script.Parent.Parent.FG1:WaitForChild("S_SEVEN",100).Motor
local s8 = script.Parent.Parent.FG1:WaitForChild("S_EIGHT",100).Motor
local s9 = script.Parent.Parent.FG1:WaitForChild("S_NINE",100).Motor
local s10 = script.Parent.Parent:WaitForChild("S_TEN",100).Motor
local s11 = script.Parent.Parent:WaitForChild("S_ELEVEN",100).Motor
local s12 = script.Parent.Parent:WaitForChild("S_TWELVE",100).Motor
local islevel1 = script.Parent.Parent.retractr.islevel




function rspoilerlevel2()
	
	
rt4.DesiredAngle = 0
	rt3.DesiredAngle = 0	
	rt2.DesiredAngle = 0
    rt1.DesiredAngle = 0
    s1.DesiredAngle = 0
s2.DesiredAngle = 0
s3.DesiredAngle = 0
s4.DesiredAngle = 0
s5.DesiredAngle = 0
s6.DesiredAngle = 0
s7.DesiredAngle = 0
s8.DesiredAngle = 0
s9.DesiredAngle = 0
s10.DesiredAngle = 0
s11.DesiredAngle = 0
s12.DesiredAngle = 0
script.Parent.Parent.RThrustBackground.BackgroundColor3 = Color3.new(255,0,0)
islevel1.Value = true


	
	
	
	
end


function onClicked()
	if islevel1.Value == false then
		rspoilerlevel2()
	
		
	
		
		
		
	end
	
	
end

script.Parent.MouseButton1Click:connect(onClicked)





Extending

local rt4 = script.Parent.Parent.FG1:WaitForChild("RT_FOUR").Motor
local rt3 = script.Parent.Parent.FG1:WaitForChild("RT_THREE").Motor
local rt2 = script.Parent.Parent.FG1:WaitForChild("RT_TWO").Motor
local rt1 = script.Parent.Parent.FG1:WaitForChild("RT_ONE").Motor
local s1 = script.Parent.Parent.FG1:WaitForChild("S_ONE").Motor
local s2 = script.Parent.Parent.FG1:WaitForChild("S_TWO").Motor
local s3 = script.Parent.Parent.FG1:WaitForChild("S_THREE").Motor
local s4 = script.Parent.Parent.FG1:WaitForChild("S_FOUR").Motor
local s5 = script.Parent.Parent.FG1:WaitForChild("S_FIVE").Motor
local s6 = script.Parent.Parent.FG1:WaitForChild("S_SIX").Motor
local s7 = script.Parent.Parent.FG1:WaitForChild("S_SEVEN").Motor
local s8 = script.Parent.Parent.FG1:WaitForChild("S_EIGHT").Motor
local s9 = script.Parent.Parent.FG1:WaitForChild("S_NINE").Motor
local s10 = script.Parent.Parent:WaitForChild("S_TEN").Motor
local s11 = script.Parent.Parent:WaitForChild("S_ELEVEN").Motor
local s12 = script.Parent.Parent:WaitForChild("S_TWELVE").Motor
local islevel1 = script.Parent.Parent.retractr.islevel


function espoilerlevel2()
	
	
rt4.DesiredAngle = 1.5
	rt3.DesiredAngle = 1.5	
	rt2.DesiredAngle = 1.5
    rt1.DesiredAngle = 1.5
    s1.DesiredAngle = -0.6
s2.DesiredAngle = -0.6
s3.DesiredAngle = -0.6
s4.DesiredAngle = -0.6
s5.DesiredAngle = -0.6
s6.DesiredAngle = -0.6
s7.DesiredAngle = -0.6
s8.DesiredAngle = -0.6
s9.DesiredAngle = -0.6	
s10.DesiredAngle = -0.6
s11.DesiredAngle = -0.6
s12.DesiredAngle = -0.6
script.Parent.Parent.RThrustBackground.BackgroundColor3 = Color3.new(0,255,0)
islevel1.Value = false

	
	
	
	
end


function onClicked()
	if islevel1.Value == true then
		
		espoilerlevel2()
	
		
		
		
	end
	
	
	
end

script.Parent.MouseButton1Click:connect(onClicked)








islevel is a bool value.

Thanks for your responses!

2 comments

0

Please use a table and get children in this script. I don't want to look through over 100lines of code