Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

2 comments

0

22:07:30.442 - Attempt to connect failed: Passed value is not a function

0

That should work. If it doesn't, then you're doing something wrong.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.