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

attempt to call a nil value?

Hey guys so I have been making a code that will enlarge a on screen gui in a fancy way, currently just testing to see if it works but I can't get it to work. Whenever I click the start button it says in output attempt to call a nil value!

Here is the code:

Start = script.Parent.StartButton
CourseSelect = script.Parent.CourseSelect
Start.MouseButton1Down:connect(ClickedStart)
target = game.Workspace.SpawnLocation
camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
angle = 0
go = 0

-- Size X 400, Size Y 300

camera.CoordinateFrame = CFrame.new(target.Position)
					   * CFrame.new(20, 5, 20)
					   * CFrame.Angles(0, -.3, 0)
					
function ClickedStart()
	for GuiSize = 1, 30 do	
		if GuiSize <= 30 then
			CourseSelect.Size = CourseSelect.Size +UDim2.new(0.05, 0.05, 0, 0)
		end
	end
end

It's in a local script and I'm kinda new so if anyone has any suggestions. This is basically suppose to change the camera angle and when you click start make a little textbox open in a fancy way!

1 answer

You have to put the connection line:

Start.MouseButton1Down:connect(ClickedStart)

After the function that it is connecting to.

function ClickedStart()
	for GuiSize = 1, 30 do 
		if GuiSize <= 30 then
			CourseSelect.Size = CourseSelect.Size +UDim2.new(0.05, 0.05, 0, 0)
		end
	end
end
Start.MouseButton1Down:connect(ClickedStart) -- Here

If you don't, the script won't know that "ClickedStart" is the function. It will just say it's nil.

2 comments

0

Thanks! This works, one more question, is there a way to make a for statement that will continue until CourseSelect reaches a certain size?

0

Bman8765: A while loop is more appropriate. E.g., while CourseSelect.Size.Scale.X < 0.5 do

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