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

Attempt to connect failed, passed value isn't a function?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

I'm trying to connect a function when a variable is true and disconnect when you press x

I keep getting this error:

Attempt to connect failed: Passed value is not a function 23:12:22.419 - Script 'Players.Player.PlayerScripts.Placing', Line 19

--//Predefines
local uis = game:GetService("UserInputService")

--//Variables
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Camera = game.Workspace.CurrentCamera
local Database = game.ReplicatedStorage
local Mouse = Player:GetMouse()
local itemGui = Player.PlayerGui.Guis.Items

local currentlyPlacing = false

--//Item placing
function updatePlacingPosition(position)
    print(position)
end

local placing = Mouse.Changed:connect(updatePlacingPosition(Mouse.hit.p))
placing:disconnect()

    --//Item placing buttons
    for i,v in pairs (itemGui:GetChildren()) do
        v.MouseButton1Down:connect(function()
            currentlyPlacing = true
            placing:connect()
        end)
    end

    --//Item disconnecting button
    uis.InputBegan:connect(function(input, typing)
        if not typing and input.UserInputType == Enum.UserInputType.Keyboard then
            if input.KeyCode == Enum.KeyCode.X then
                placing:disconnect()
            end
        end
    end)

1 answer

Log in to vote
1
Answered by 8 years ago

You need to pass connect a function, you're passing it nothing, nil.

To get what you're trying to do create another function

local placing = Mouse.Changed:connect(function() updatePlacingPosition(Mouse.hit.p) end)

Buuuuuttttt the other parts of the script wont work either, if you want something to run only sometimes you can connect it to a loop and have a conditional

local running = true --set this to false and it wont run the function when the event is fired

local placing = Mouse.Changed:connect(function() 
if running then
updatePlacingPosition(Mouse.hit.p)
end
end)
Ad

Answer this question