Datastore for all gangs

so i am making a gang system and ive ran into a problem with filtering through all the current gangs i was about to make a system with datastore2 for all the gangs but its only for players so i thought of using profile service or some external data thingy wat ur guys thoughts

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local TextService = game:GetService("TextService")
local ErrorModule = require(ServerStorage.Modules.Error_Message)
local DataStore2 = require(ServerStorage.Modules.DataStore2)
local GangCreate = ReplicatedStorage.RemoteEvents.GangCreate
local GangLeave = ReplicatedStorage.RemoteEvents.GangLeave
local GangKick = ReplicatedStorage.RemoteEvents.GangKick
local GangJoin = ReplicatedStorage.RemoteEvents.GangJoin

GangCreate.OnServerEvent:Connect(function(player,gangname)
	if gangname:match("%s") then
		ErrorModule.Function(player,"Gang Name has spaces pls remove")
	else
		if string.len(gangname) <= 12 then
			local filteredTextResult
			local success, errorMessage = pcall(function()
				filteredTextResult = TextService:FilterStringAsync(gangname, player.UserId)
			end)
			if success then
				
				
				-- check somewhere to see if theres another gang that has a same name
				
				
			else
				ErrorModule.Function(player,"Gang Name is censored enter a new one")
			end
		else
			ErrorModule.Function(player,"Gang Name has more then 12 characters pls shorten it")
		end
	end
end)

GangLeave.OnServerEvent:Connect(function(player)
	
end)

GangKick.OnServerEvent:Connect(function(player,playertokick)
	
end)

GangJoin.OnServerEvent:Connect(function(player,gangname)
	if string.len(gangname) <= 12 then
		local filteredTextResult
		local success, errorMessage = pcall(function()
			filteredTextResult = TextService:FilterStringAsync(gangname, player.UserId)
		end)
		if success then
			
			
			
			
		else
			ErrorModule.Function(player,"Gang Name is censored enter a new one")
		end
	else
		ErrorModule.Function(player,"Gang Name has more then 12 characters pls shorten it")
	end
end)

Ok first (this is my opinion).why are you not using a regular datastore. (Ik it can havee data loss.sorry if it was obvious).

Now lets come to ur topic.

So i see you are trying to check if theres a gang name occupied already (sry if im wrong).

You can create a key with gang name and call getasync (or how everr u get data in DS2) and if the result is 0 then u can give them that id and add a Tag named “Occupied”.just so u can check for the else statement because its possible that gang has corrupt data or has made no progress.

For starters…
image
Now that that’s out of the way, please make your post more specific. You have not given any info as to what your problem is.

1 Like

mb i forgot that i am talking to an lead programmer at boba cafe i am very sorry that i have added a gang system in my game ill change it to factions. so anyways in the remoteevent to make a gang it checks if theres any other gang with the same name so i was wondering how i would do it thru regular datastore,external data saving thing ect

For normal datastore.

local DSS = game:GetService("DatastoreService"):GetDatastore ("Faction-DataStore")

function CheckFactionExists(Name)
local pcallStatus,Return = pcall(function()
DSS:GetAsync(Name)
end)
if pcallStatus and Result["Occupied"] then
return true
elseif pcallStatus and Result == 0 then
return false
elseif not pcallStatus then
warn("There was a Error Experienced by the Script while Trying to Access Data./nERROR: "..Result)
return "Error"
end
end)

External Servers.

Read a Article on HTTP Service because it can’t be explained directly.
Also make sure u have a website/server for it.

thanks i got a idea of wat to do

GangCreate.OnServerEvent:Connect(function(player,gangname)
	if gangname:match("%s") then
		ErrorModule.Function(player,"Gang Name has spaces pls remove")
	else
		if string.len(gangname) <= 12 then
			local filteredTextResult
			local success, errorMessage = pcall(function()
				filteredTextResult = TextService:FilterStringAsync(gangname, player.UserId)
			end)
			if success then
				
				local Available
				local success, errormessage = pcall(function() --getting loaded data
					Available = AllGangData:GetAsync(gangname)
				end)
				if success then
					if Available == nil then
						print("no gangs with same name good to go")
					else
						ErrorModule.Function(player,"Gang Name is taken")
					end
				end

				
				-- check somewhere to see if theres another gang that has a same name
				
				
			else
				ErrorModule.Function(player,"Gang Name is censored enter a new one")
			end
		else
			ErrorModule.Function(player,"Gang Name has more then 12 characters pls shorten it")
		end
	end
end)