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

Attempt to connect failed: Passed value is not a function?

Asked by 10 years ago

I have an error on line 29. which is script.Parent.ClickDetector.MouseClick:connect(onClick)

Please may you help me with this? Has there been an update or something?

My error is Attempt to connect failed: Passed value is not a function

This is the whole script:

debounce = false

function raiseone()
    for i= 1,71 do
    script.Parent.DoorOne.CFrame = script.Parent.DoorOne.CFrame + Vector3.new(0,0.1,0)
    wait(0.02)
end

function raisetwo()
        for i= 1,71 do
    script.Parent.DoorTwo.CFrame = script.Parent.DoorTwo.CFrame + Vector3.new(0,0.1,0)
    wait(0.02)
end

function onClick()
    if debounce == false then
        debounce = true
    game.Workspace.BarDoor.BarButton.BrickColor = BrickColor.Red()
    spawn(raiseone)
    spawn(raisetwo)
    wait(25)
    game.Workspace.BarDoor.BarButton.BrickColor = BrickColor.Green()
    debounce = false
    end
    end
end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

1 answer

Log in to vote
1
Answered by 10 years ago

The issue here is purely do to lack of proper endings. If you note your first function (raiseone), it lacks an ending. There should be one ending to end the for-loop and one to end the function. Currently you only end the for-loop. That means the next function is created inside the first function, and the problem persists through this function too. And then you have a lot of ends at the bottom to catch up. Bad habit and certainly not what you aimed for!

The fix is simple - move the overflowing ends from the bottom to their respective positions.

debounce = false

function raiseone()
    for i= 1,71 do
    script.Parent.DoorOne.CFrame = script.Parent.DoorOne.CFrame + Vector3.new(0,0.1,0)
    wait(0.02)
    end
end

function raisetwo()
     for i= 1,71 do
           script.Parent.DoorTwo.CFrame = script.Parent.DoorTwo.CFrame + Vector3.new(0,0.1,0)
           wait(0.02)
     end
end

function onClick()
    if debounce == false then
        debounce = true
    game.Workspace.BarDoor.BarButton.BrickColor = BrickColor.Red()
    spawn(raiseone)
    spawn(raisetwo)
    wait(25)
    game.Workspace.BarDoor.BarButton.BrickColor = BrickColor.Green()
    debounce = false
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)
0
THANK YOU SENPAI! GIVE ME ATTENTION SENPAI! ;D ;D ;D ;D. no srsly tho. thx :) WelpNathan 307 — 10y
Ad

Answer this question