Hello.
In my game I'm trying to implement a system for grabbing objects. I've created a custom class to define these items like so;
(Module script)
local exampleItem = {}
exampleItem.__index = exampleItem
function exampleItem.new()
local example = setmetatable({},exampleItem)
local part = Instance.new("Part")
part.Name = "PartA"
part.Parent = workspace
example.Part = part
return example
end
function exampleItem:Grab()
print("Item was grabbed")
end
Then I want to fire the "Grab" function from another script, but I haven't found a way to do so.
What I mean is something like this;
(In another script)
workspace.PartA:Grab()
In short I want to be able to associate or "attach" the table to the part so that I can reference it from knowing only the part.
I've looked around on the forums and the only solution I could find was to store all created items in a table, and then give the part an ID which would refer to the item in the table. However, this solution seems a bit convoluted and looks quite prone to memory leaks. So I'm wondering, is there a simpler solution which would make firing the function more direct?
Thanks.

2 comments
oops... i messed up some of the code lines, im sure youll be able to tell whats code either way (on the part that the code it to be instead of the print thing)
Thanks for the help! Upon further investigation it seems that the method I mentioned (giving instances IDs) is the simplest, so I'm going to try implementing that. Anyway, thank you.