#Sect/Guild System Improvement help

1 messages · Page 1 of 1 (latest)

dusk sand
#

How do you write systems like guilds in a datastore

I usually write them in as

GlobalData = [Guilid] = { guildname,guild members = [UserId]. = Rankname, etc}

dusk sand
#
local DTS = game:GetService("DataStoraService")
local GS = DTS:GetDataStore("GuildStorage")
local currentkey = "Beta"
local module = {}

local function getguilds()
  local sucess , data = pcall(function()
    return GS:GetAsync(currentkey)
   end)
  if not sucess then
   print("fialed to get data deu to unknown errors")
     return nil
  return data
end

local function saveguilds(guildstosve)
  local success,err = pcall(function()
    GS:SetAsync(currentkey,guildstosave)
  end)
  if not success then 
    print("failed to save data"
  end
end


function module:GetGuildName(guildid)
   local guilds = getguilds()
    if guilds[guildid] then
     return guild[guildi]
    
end

function module:CreateGuild(guildid, Name, creator)
    local guilds = getguilds()
    for id, guild in pairs(guilds) do
        if guild.Name == Name then
            return false, "name is allready taken"
        end
    end
    
    guilds[guildid] = {
        Name = Name,
        Members = {[creator.Id] = "Leader"},
        RequestedMembers = {}, -- well be conenig players the leder reqested to join
    }
    saveguilds(guilds)
end

function module:AddMember(guildid, playerid, requesterid)
    local guilds = getguilds()
    
    if not guilds[guildid] then return false, "Guild not found" end
    if guild.Members[requesterid] ~= "Leader" then return "does not have permission to add a player" end
    for id, guild in pairs(guilds) do
        if guild.Members[playerid] then
            return false, "Player already in a guild"
        end
    end
    guild.RequestedMembers[playerid] = "Member"
    saveguilds(guilds)
end

function module:RemoveMember(guildid,playerid,requesterid)
   local guilds = getguilds()
    
    if not guilds[guildid] then return false, "Guild not found" end
    if guild.Members[requesterid] ~= "Leader" then return "does not have permission to add a player" end

    guild.RequestedMembers[playerid] = nil
  
    saveguilds(guilds)
end

function module:DestroyGuild(guildid,requesterid)
   local guilds = getguilds()
    
    if not guilds[guildid] then return false, "Guild not found" end
   guilds[guildid] = nil
   saveguilds(guilds)
end

return module

tough shadow
#

first of all.

#
   print("fialed to get data deu to unknown errors")
     return nil
  return data``` u forgot end
dusk sand
#

mb

#

i wrote it in here so...

tough shadow
#

tf

#

let me

#

read it

#

i might be hight

#
   local guilds = getguilds()
    
    if not guilds[guildid] then return false, "Guild not found" end
   guilds[guildid] = nil
   saveguilds(guilds)
end``` wont do anything
#

@dusk sand

dusk sand
#

thats it...

tough shadow
#

?

#

why are u saving the guilds back

dusk sand
#

idk 😭

#

i forgot

#

leme reread

tough shadow
#

holy

dusk sand
tough shadow
#

wont do anything

dusk sand
#

so what to do ?

tough shadow
#

you're jst saving the guild back without any changes

dusk sand
#

guilds[guildid] = nil
...

tough shadow
#

this returns a table

#

local guilds = getguilds()

dusk sand
#

ye

tough shadow
#

you're setting a table value

#

not the DATA store value

dusk sand
#

ye

#

saveguilds saves it ?

#

i give the guilds to saveguilds

tough shadow
#

oh yea f

#

i need sum sleep

dusk sand
#

lol

tough shadow
#

told u im high

dusk sand
#

i tho something was wrong lol

tough shadow
#

someone might help u later

#

be patience

#

i need to go