Gang system isn't working

Hello guys. I’m trying to create a gang system like in YBA (roblox game I don’t know if any of you played this). The system will work like this: you will create a gang with some criteria and when you manage to do that, the script will create a new StringValue (with instance.new). The Valor name is the gang name and the New Valor value is the gang password. It’s not the problem, now I need to save the gangs that were created in the game, so when the server shuts down you can join or when you create something like your friend can join without shutting down the server on another server. I tried using the script below but it didn’t work because when trying to GetAsync on a new server it doesn’t have a value to set Async because the value doesn’t save. I really don’t know how to fix and do this, I’m not a beginner but I don’t know bro, I guess I’m dumb?

local Sucesso, Resposta = pcall(function()
	
	warn("Carregando gangues...")
	local DSService = game:GetService("DataStoreService")
	local GangStore = DSService:GetDataStore("Gangs")
	local Gangues = game.ReplicatedStorage:WaitForChild("Gangs")
	wait(1)
	local stats = Gangues:GetChildren()
	for i = 1, #stats do			
		stats[i].Value = GangStore:GetAsync(stats[i].Name) or GangStore:SetAsync(stats[i].Name, stats[i].Value)
	end
	
	
end)
if not Sucesso then
	warn("As gangues do jogo não foram carregadas corretamente.")
else
	print("As gangues do jogo foram carregadas corretamente.")
end

game:BindToClose(function()
	warn("Salvando gangues...")
	local Sucess2, Resposta2 = pcall(function()
		local DSService = game:GetService("DataStoreService")
		local GangStore = DSService:GetDataStore("Gangs")
		local Gangues = game.ReplicatedStorage:WaitForChild("Gangs")
		
		local statstorage = Gangues:GetChildren()
		for i =  1, #statstorage do
			GangStore:SetAsync(statstorage[i].Name, statstorage[i].Value)
		end
		
	end)
	
	if not Sucess2 then
		warn("As gangues do jogo não foram salvas corretamente.")
	else
		print("As gangues do jogo foram salvas corretamente.")
	end end)

You best choice is to have a table local Gangs = {} and save it with datastore and loop through itz if you want it to go through all the servers in the game use MessagingService

1 Like

Thank you so much bro! I didn’t think in it.

1 Like

Your welcome, Glad I was able to help!

1 Like

Sorry for disturbing but to acess the table through another scripts I use modulescript, correct?

Yes, or you can do _G.Table but a Module script is your best choice.

1 Like

Ok, thanks again! You helped me a lot.

1 Like

Hello, bro! I don’t know if you still there, but how to I (in a table) insert two informations? Like the gang name and the gang password. Furthermore, I need to put the table in a GlobalDataStore or just in a DataStore?

local GangHandler = {}
local GangTable = {
	
	DevGang = "123"
	
}

function AddGang(Name, Password)
	if Name ~= nil and not Name:match("%s") then
		table.insert(GangTable, Name)
	end
end

return GangHandler

Sry for the late reply, just do this

local gangs = {
	gang1 = {
		Name = "ABC"; --remember you MUST have the semicolon or it will have red lines and error
		Owner = "Someone";
	}:
{

--Testing so you understand more.
local Owner = gangs.gang1.Owner
local Name = gangs.gang1.Name
print(Owner , Name)
1 Like

Do you have Discord? I really want to talk with you.

Yes, Msix29#7740
Feel free to ask any questions!

1 Like

Sent friend request! I need your help please :smiley:

1 Like