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

Assigning an argument through Connect() ?

I have this code:

local function a(n)
	return n
end

local b = game.Workspace.Button2.Button.ClickDetector.MouseClick:Connect(a("Test"))
print(b)

It should call the function a and pass "Test" to it, but an error occurs when the script is run:

Attempt to connect failed: Passed value is not a function

Yet, this does the same thing and still works:

local function a(n)
	return n
end

print(a("Test"))

1 comment

0

Can't answer due to the 1.5 minute cooldown, but from what I know, you can only pass functions into the Connect function.

1 answer

✓ Accepted answer

You used :Connect wrong. If you want to execute a function with custom parameters, you'll have to call the function inside of the ClickDector function. Here's the code:

local function b(n)
	print(n)
end

game.Workspace.Button2.Button.ClickDetector.MouseClick:Connect(function()
 b("Test")
end)

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