How do i make gangs system?

Is this Script? Or Local Script?

This is a script, you can only access datastores through scripts. If you want to get it on the client, use a remote function, invoke the server, and have the server return the gangs.

Okay thanks lemme try that. (30 letters)

Hello so after a week of creating i finally work on that part, how do i should add GANGS to GANGS variable each time plr create a new gang?

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)	

Im Guessing the one similar to Roblox Wild west

GLHF hope this helped you :smile:

I think no because i need a Entire servers gang system not on one server

I need to somehow save to datastore gangs names

I think i should add a value in datastore somehow

1 Like

So, if it is a table in the datastore, you could insert the gang name into the datastore by doing:

gangds:SetAsync("key", table.insert(gangds:GetAsync("key"), name))

Typing out a long reply, give me 20min.

Ohh then i should get a player text from textbox and make it in datastore

1 Like

Wait how do i get which text player wrote in textbox?

pass it along with the remote event.

event:FireServer(textbox.Text)

and receive it like this:

event.OnServerEvent:Connect(function(plr, name)

Breeh but i alr have a on server event with Gang Remote event

Just add it as another variable on the OnServerEvent

Hmmm wait, but it will fireserver with textbox text nil, because by default is nil , i need after player entered a name and clicked enter(idk)

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
1 Like

My god, that looks so hard omg

Its not to complex, just read the code.