Need help for guild system

Hi, i make a guild system and i have a problem, when a player create a guild, if the guild name already exist i wan’t to tell the player, but what i can make for loop the existing guild ? when a player create a guild the guild name is stored in datastore “GuildSaveSystem” with a stringvalue in leaderboard

Sans titre

Thank you for your help

3 Likes

You should be creating a table for each guild name that is created. A datastore to go along with that table (or save it in another datastore. up to you).

Everytime a player tries to create a guild it will loop through the table and see if the name is taken or not.

Have you an exemple for creating table ? i don’t know how make this :thinking:

Well you set up a datastore first if you don’t have one already:

local DataStoreService = game:GetService('DataStoreService')
local GuildDataStore = DataStoreService:GetDataStore('GuildNames', 1)

local GuildNames = {} -- Obv change this to work with your datastore

Then you’ll need to set up a MouseButton1Click function in a local script for when the Create Guild button is clicked, which will fire a Remote Function passing whatever text is in the textbox as a parameter.

You’ll have to set up a function connecting to OnServerInvoke specifically for that event you fired from the client, and that function will have to loop through the table using a:

for i,v in pairs(GuildNames) do
    -- code here
end

and if the name is found, then return a true or false to client and go from there.

1 Like

I have make this but print is’nt fire… :confused: (info is the name of the guild)

local re = game.ReplicatedStorage.guilde
local DataStoreService = game:GetService('DataStoreService')
local GuildDataStore = DataStoreService:GetDataStore('guild_Names', 1)

local GuildNames = {}

local function onTable(player, info)
	for i,v in pairs(GuildNames) do
    	if info then
			print("Exist")
		else
			print("created")
		end
	end
end

re.OnServerEvent:Connect(onTable)

If you’re saving the guild information (including name) directly to a DataStore, you can simply see if that key already exists.

For example, if you set a key inside a DataStore with the name of the guild being the key (value can be whatever information is required to be stored), you can simply do something like:

local isTaken=GuildDataStore:GetAsync(guildName)~=nil

This will return true if the key exists within the DataStore, which will allow you to determine whether the guild name is taken or not.

1 Like

I don’t understand ?

My saving guild is here:

local ds8 = datastore:GetDataStore("GuildSaveSystem")
local guilde = Instance.new("StringValue")
guilde.Name = "Guilde"
guilde.Value = ""

so i make your code but guildname is not understand by script :thinking:

Sans titre

Yeah, what I meant was you’d replace it with your own stuff. My code was just an example.
Here’s a working example that should work fine for your use case.

local re=game:GetService("ReplicatedStorage"):WaitForChild("guilde")
local dss=game:GetService("DataStoreService")
local gds=dss:GetDataStore("GuildSaveSystem")

local function onTable(player,guildname)
	local isTaken=gds:GetAsync(guildname)~=nil
	if isTaken then
		print("guild name is taken")
	else
		print("guild name is not taken, creating")
		gds:SetAsync(guildname,{})
		-- you can store whatever data you need to within that table like the guild creator etc. etc.
		-- to index that information, try doing gds:GetAsync(guildname)
	end
end

re.OnServerEvent:connect(onTable)
3 Likes

Thank you, for index the creator i need to change this:

gds:SetAsync(guildname,{})

for this ?

gds:SetAsync(guildname,player)

You’d include it within the table, like so:
gds:SetAsync(guildname,{creator=player.UserId})
So then, if you want to check who the creator is at some other point, you can do this:
gds:GetAsync(guildname).creator to index the creator’s user id (as storing the player instance itself wouldn’t work)

I can’t keep consistently helping you out with making the entire system. I encourage you to try and accomplish it yourself with resources from the wiki, that way you’ll learn how things work and why things need to be formatted in specific ways etc. etc.

1 Like

Ok but if i want make a specific action for the creator of the guild when he’s connect to server, i have this but guildname is unknown :confused:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
	local t
	local success, e = pcall(function()
		t = gds:GetAsync(guildname).creator
	end)

ayy this heleped thx alot :smiley: i was trying to make one my self but i couldnt figure out how so this is a big help

You can use a OrderedDataStore. That’ll help.