So this is my script where i should get when player create gang
local GangCEvent = game.Workspace.GangsEvents.GangCEvent
local dss = game:GetService("DataStoreService")
local gangds = dss:GetDataStore("GangNames")
GangCEvent.OnServerEvent:Connect(function()
print(gangds:GetAsync("key"))
end)
local Gangs = {}
local DS = game:GetService("DataStoreService")
local HTTP = game:GetService("HttpService")
local Store = DS:GetDataStore("Gangs_1")
local ActiveGangs = {}
local GangMethods = {} --- Using Metatbles for this.
GangMethods.__index = GangMethods
--- Core with gang internals.
function GangMethods:AddPlayer(PlayerToAdd)
assert(not PlayerToAdd, "No player given. Cant add nil value.")
table.insert(self.Players, PlayerToAdd.UserId)
end
function GangMethods:RemovePlayer(PlayerToRemove)
assert(not PlayerToRemove, "Cannot remove nil player.")
local Player_Index = table.find(self.Players, PlayerToRemove.UserId)
table.remove(self.Players, Player_Index)
end
function GangMethods:Upgrade() -- Idk how you wanna handle this
-- Do upgrade stuff here
print(self.Upgrades)
end
--- All other Core stuff here.
function DefaultGangInfo(Owner, GangName) -- Default Gang Info
return {
Owner = Owner;
Name = GangName;
GangID = HTTP:GenerateGUID();
Players = {}; -- by userid
Upgrades = {
["Health"] = 1; -- Upgrade Name Level.
};
}
end
function CheckGangExist(GangName)
return Store:GetAsync(GangName) and true or false
end
function Gangs.Create(Owner, GangName) -- When player wants to create a new Gang.
assert(not GangName, "No name given! Cannot create a Gang with no name!")
assert(not Owner, "Cannot create gang without owner.")
local GangInfo
if not CheckGangExist(GangName) then -- Check if Gang exists.
GangInfo = DefaultGangInfo(Owner, GangName)
Store:UpdateAsync(Owner.UserId, function(Old)
return GangInfo -- save new gang to Gang list.
end)
end
return setmetatable(GangInfo, GangMethods)
end
function Gangs.Load(Owner)
local GangData = Store:GetAsync(Owner.UserId)
local GangMeta
if GangData then
GangMeta = setmetatable(GangData, GangMethods)
ActiveGangs[GangData.GangID] = GangMeta
end
return GangMeta
end
return Gangs
I was trying to figure out a way to not use OOP but it would require a lot of extra memory usage. So, this solution that was the most efficient was this choice, lol.
@PhantomGame_Youtube I have a link to a post I made regarding the theory behind OOP. I will post it below: