Greetings,
**Context **: I want to create what I call Citizens, which require a physical representation (a part), but also custom properties (ex : GridPosition, Age, CurrentTask...).
What I tried :
- Creating a Citizen object, and creating a Model property containing a Part object (obtained from ReplicatedStorage). *Issue *: When setting the parent of the part to workspace (to move the citizen), there is no reference to the citizen object (from the part), which is an issue. Code :
Citizen.__index = Citizen
function Citizen.new()
local newCitizen = {}
setmetatable(newCitizen, Citizen)
newCitizen.Model = game.ReplicatedStorage.Models.Citizen -- a Part Object
-- custom properties... (newCitizen.Age...)
return newCitizen
end```
- Creating a Citizen object, which is the actual Part object from ReplicatedStorage, and adding custom attributes to it. *Issue *: the Part is an instance and not a table, I can therefore not use setmetatable (or do not know how to obtain a table from an instance). Code :
```local Citizen = {}
Citizen.__index = Citizen
function Citizen.new()
local newCitizen = game.ReplicatedStorage.Models.Citizen -- Part Object
setmetatable(newCitizen, Citizen) -- invalid argument : table expected
-- custom properties
newCitizen:SetAttribute("GridPosition", Vector2.new(0, 0)
newCitizen:SetAttribute("Age", 0)
return newCitizen
end```
**Question **: Is there any way to do something like this in a clean way? Is it possible to inherit from a class like Part/BasePart? I basically want to create an object but have a physical representation (Part/Model) linked to it, and other custom properties, while being able to manipulate all of these easily with methods of mine (like Citizen:Move, Citizen:SetTask...).
If you need any other precision please ask me.
** You are now Level 1! **