I'm trying to call a custom function through a button click connection and I want to pass an argument to the function but I'm getting an error that says the passed value (AddQuant('Food')
) is not a function. What do I need to do to pass that argument? I don't want to use an anonymous function, and I've already checked spelling and capitalization. Anyways, here's the connection line and function.
--The function function AddQuant(type) amount[type] = amount[type] + incriment[type] Labels[type].Text = "Food: " .. amount[type] end ] --The connection line Buttons['Food'].MouseButton1Click:connect(AddQuant('Food'))
Thanks for any help.
-GoldenPhysics
Edit: added function being called.
When you connect an event, it adds its own parameters based on the event. Attempting to add your own via the connection line will produce an error. A solution is to call your named function with an anonymous function, like this:
--The function function AddQuant(type) amount[type] = amount[type] + incriment[type] Labels[type].Text = "Food: " .. amount[type] end ] --The connection line Buttons['Food'].MouseButton1Click:connect(function() AddQuant('Food') end)