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

How do I set an argument when trying to connect a function?

Asked by 8 years ago
function toggle(v)
    print(v)
end
door = game.Workspace.Door
door.Handle.ClickDetector.MouseClick:connect(toggle)

Im trying to set the v argument in toggle to the variable door

2 answers

Log in to vote
0
Answered by 8 years ago

To set an argument when calling a function, add '()' onto the end, with the value that you want inside. E.G:

function toggle(v)
    print(v)
end
door = game.Workspace.Door
door.Handle.ClickDetector.MouseClick:connect(toggle("Value"))

It will print: Value

BUT that didn't work, so:

function doStuff(v)
    print(v)
end
function toggle()
    doStuff("Value")
end
door = game.Workspace.Door
door.Handle.ClickDetector.MouseClick:connect(toggle)

(You don't need to do this unless the value is something that didn't trigger the event that fired the function)

0
22:07:30.442 - Attempt to connect failed: Passed value is not a function User#8349 0 — 8y
0
That should work. If it doesn't, then you're doing something wrong. TheDeadlyPanther 2460 — 8y
Ad
Log in to vote
0
Answered by
shayner32 478 Trusted Moderation Voter
8 years ago

Hi there. What you're trying to do isn't what you NEED to do. Basically, you're connecting a function to a click event from a ClickDetector. This will pass along the player who clicked the ClickDetector, not the part they clicked. Printing v would return a table or error, not too keen. Basically, what you want to do is this:

door = game.Workspace.Door -- When you get a chance, put the script in the door, and change this to script.Parent!

function toggle(v)
    -- Insert code here! For example: door.Transparency = 1
    print("A player named "..v.Name.." has clicked the ClickDetector!")
end

door.Handle.ClickDetector.MouseClick:connect(toggle)

Answer this question