Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to call a nil value?

Asked by
Bman8765 270 Moderation Voter
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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.

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? Bman8765 270 — 9y
0
Bman8765: A `while` loop is more appropriate. E.g., `while CourseSelect.Size.Scale.X < 0.5 do` BlueTaslem 18071 — 9y
Ad

Answer this question