You can set entity specific variables by storing it in the entity the same way you would a table. Say your variable is a number, you could do [entity].MyNumber = 1, where [entity] is your entity object. You can then at any time access and change these individually on each entity by doing [entity].MyNumber again. It should be noted that you don’t have to define these in ENT: functions, you can do [entity].variable anywhere you have its entity object, and this goes for all entities, even players.
[lua]-- in Entity B
self.MyNumber = 2
– Somewhere else in Entity B
function ENT:Use(ent, caller)
self.MyNumber = self.MyNumber + 1
– Count 1 up every time someone uses it
– Then to get the information on Entity A (This is in Entity A’s code)
if IsValid(ent) and ent:GetClass() == “YourEntityName” then – Make sure it is indeed one of Entity B
self.LastTouchedEntsNumber = ent.MyNumber
– self = Entity A, and ent = Entity B in this case
The above example shows how you could set a variable on each individual Entity Bs, which will then increase by 1 each time they’re used (press E), resulting in them having different numbers. Later, when Entity A touches Entity B, you can get that variable from that entity since you have got its entity object (basically the entity itself in the code, here it’s “ent”). It then sets Entity A’s variable to what that particular Entity B had.