Hi I'm trying to do a big project here, and one of the things required is to sucessfully send in a function to be read by another modulescript and executed. This is so I can tie function to an event with more flexibility, allowing me to change the effect of a button when created.
Here's what I have
local GUI = {} ------------------------------------------------------------------------------------------------------ --CONSTRUCTOR-- function GUI.new(PARENT, CLICKEFFECT, CARD) --------------------- --PRIVATE VARIABLES-- local name = CARD:getName(); local card = Instance.new("ImageButton", PARENT) local clickEffect = loadstring(CLICKEFFECT); local stuff = {} ------------------------------------------------------------------------------------------------------ --SETTINGS-- card.Size = UDim2.new(.2, 0, .5, 0) card.Position = UDim2.new(.2, 0, .25, 0) ------------------------------------------------------------------------------------------------------ --ACCESSOR METHODS-- function stuff:getScreenPosition() --Returns the UDim2 of the Position return card.Position end ------------------------------------------------------------------------------------------------------ --MODIFIER METHODS-- function stuff:moveGUITo(newPosition) --Moves the GUI to newPosition(a UDim2) card.Position = newPosition; end ------------------------------------------------------------------------------------------------------ --EVENT LISTENERS-- card.MouseButton1Down:connect(clickEffect) --------------------- setmetatable(stuff, GUI); return stuff end ------------------------------------------------------------------------------------------------------ --MISC METHODS- ------------------------------------------------------------------------------------------------------ --METAMETHODS-- GUI.__index = GUI --All indexes to this object will be directed to the module's items ------------------------------------------------------------------------------------------------------ return GUI
And I drive it with
local GUI = require(script.Parent.GUI); ...irrevelant code here... cards[i] = GUI.new(main, "function()print(name)end" , Deck[i])
problem is, when I run, I get the error:
1:11:13.739 - Attempt to connect failed: Passed value is not a function
and when I click it, of course I'll get
11:11:14.652 - attempt to call a nil value
Can anyone help me solve my problem? I'm looking for the most efficient way to do this