Oh boy, this is a big one. Here's what I'm trying to do.
A big object that holds a table of values creates a manager object. This "manager" object creates a GUI-based Object for every item in the big object.
When someone clicks the one of the GUI-based Objects, somehow the message needs to come back to the big object that the clicked object needs to be removed from the big object.
I'm not expecting any code, but does anyone know what kind of concept I should use to accomplish this?
Let me clarify a bit more for you. All of these objects are based off of moduleScripts
I've got a Deck Object. What is important here is the :search(x) method. Here it is to the Bones:
local Deck = {}
--------------------------------------------------
--CONSTRUCTOR--
function Deck.new(...)
local cards ={...}
return setmetatable(cards, Deck)
end
--------------------------------------------------
--MISC METHODS--
function Deck:search(x) --Looks for x amount of cards
--Create new GUIBlock Object and waits for its descendants to be clicked
end
--------------------------------------------------
--METAMETHODS--
Deck.__index = Deck --All indexes to this object will be directed to the module's items
--------------------------------------------------
return Deck
Here is the "manager" object to the bones. It is named GUIBlock, as it creates many GUI's off of Deck.
local GUIBlock = {}
function GUIBlock.new(Deck, Player)
---------------------
--PRIVATE VARIABLES--
local main = Instance.new("ScreenGui", Player.PlayerGui)
local cards = {} --This will be filled with lots of GUI objects
local stuff = {}
--------------------------------------------------
--SETTINGS--
for i, v in ipairs(Deck) do
cards[i] = GUI.new(main, function()print(i)end , Deck[i]) --function right here is a sample. It prints the index of the item in the Deck object when called on
cards[i]:moveGUITo(cards[i]:getScreenPosition() + UDim2.new((i-1)*.2,0,0,0));
end
---------------------
setmetatable(stuff, GUI);
return stuff
end
--------------------------------------------------
--METAMETHODS--
GUIBlock.__index = GUIBlock --All indexes to this object will be directed to the module's items
--------------------------------------------------
return GUIBlock
And now the GUI related object itself
local GUI = {}
--------------------------------------------------
--CONSTRUCTOR--
function GUI.new(PARENT, CLICKEFFECT, CARD)
---------------------
--PRIVATE VARIABLES--
local card = Instance.new("ImageButton", PARENT)
local clickEffect = Instance.new("BindableFunction", card) --Helps to make a public instance of a sent in functions
local stuff = {}
--------------------------------------------------
--SETTINGS--
card.Size = UDim2.new(.2, 0, .5, 0)
card.Position = UDim2.new(.2, 0, .25, 0)
clickEffect.OnInvoke = (CLICKEFFECT)
--------------------------------------------------
--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(function()clickEffect:Invoke()end); --Fires the sent in function when clicked on. Its a sample
---------------------
setmetatable(stuff, GUI);
return stuff
end
--------------------------------------------------
--METAMETHODS--
GUI.__index = GUI --All indexes to this object will be directed to the module's items
--------------------------------------------------
return GUI

3 comments
And I'm not looking for any _G variable nonsense. It needs to be independent.
Look into Module Scripts
They are modulescript... The question is how you can track the Clicked event on an object throughout a hiearchy of objects