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

How do I send arguments to a function through a connection? [Solved]

Asked by 4 years ago
Edited by Ziffixture 4 years ago

hey, i want to send "W" to a function through the use of heartbeat() and it says this:

17:23:19.661 - Attempt to connect failed: Passed value is not a function

and this:

17:23:20.411 - attempt to call a nil value (x46)

this is my code:

local function rotatePart(direction)
    if direction then
        print("W")
    end
end

if shifting == true then
    heartBeat1 = runService.Heartbeat:Connect(rotatePart("W"))
end

i have a bunch of conditions surrounding this code but the problem only appears when trying to pass the argument "W" to the above function.

0
The :Connect() method takes a callback argument; is a function that is called by the signal, and fed arguments if information is supplied from the event. You’re trying to call a function in the callback argument, which is what’s causing your error. Pass the function name without parentheses. Ziffixture 6913 — 4y
0
You cannot provide an argument either, as the calling of the given function isn’t handled by you, you can optionally create a separate function which will call upon rotatePart with the arguments you desire. Ziffixture 6913 — 4y
0
thank you : D Code1400 75 — 4y

Answer this question