I’m making a guild system using ProfileService.
I’ve followed a tutorial regarding updating globally however that dealt with player data not server data but I used it regardless since I don’t know any other way.
My issue is that whenever I create/delete guilds, the global update part doesn’t work and the other servers don’t update their guild list. Moreover, they don’t even receive the active update (Tested from two accounts; one in a public server, the other in a VIP server)
-- Server script inside ServerScriptService
local ProfileService = require(script.ProfileService)
local RepStorage = game:GetService("ReplicatedStorage")
local GuildService = require(script.GuildService)
local guildRemote = RepStorage.guildRemote
local guildStore = ProfileService.GetProfileStore("testkey15355", {})
local guildList = guildStore:LoadProfileAsync("guilds", "ForceLoad")
local function handleLockedUpdate(globalUpdates, update)
local id = update[1]
local data = update[2]
if data.updateType == "Creation" then
local guildData = data.guildData
local guildName = guildData[1]
local guildInfo = guildData[2]
if not guildList.Data[guildName] then
guildList.Data[guildName] = guildInfo
end
elseif data.updateType == "DeleteAll" then
guildList.Data = {}
end
globalUpdates:ClearLockedUpdate(id)
end
local globalUpdates = guildList.GlobalUpdates
for index, update in pairs(globalUpdates:GetActiveUpdates()) do
globalUpdates:LockActiveUpdate(update[1])
end
for index, update in pairs(globalUpdates:GetLockedUpdates()) do
handleLockedUpdate(globalUpdates, update)
end
globalUpdates:ListenToNewActiveUpdate(function(id, data)
globalUpdates:LockActiveUpdate(id)
end)
globalUpdates:ListenToNewLockedUpdate(function(id, data)
handleLockedUpdate(globalUpdates, {id, data})
end)
guildRemote.OnServerEvent:Connect(function(Player, Action, ...)
if Action == "Create" then
GuildService.createGuild(guildStore, guildList, Player, ...)
elseif Action == "View" then
GuildService.viewGuilds(guildList)
elseif Action == "DeleteAll" then
GuildService.deleteAllGuilds(guildStore, guildList)
end
end)
-- Module Script inside the server script
local module = {}
function module.createGuild(guildStore, guildList, Player, guildName)
if guildList.Data[guildName] == nil then
guildList.Data[guildName] = {
Owner = Player.userId;
Members = {};
}
guildStore:GlobalUpdateProfileAsync(
"guilds",
function(globalUpdates)
print("creating active update...")
globalUpdates:AddActiveUpdate(
{
updateType = "Creation";
guildData = {
guildName,
{
Owner = Player.userId;
Members = {};
};
}
}
)
end
)
print("Created guild with name: " .. guildName)
else
warn("Guild already exists!")
end
end
function module.viewGuilds(guildList)
for i, v in pairs(guildList.Data) do
print(i)
end
end
function module.deleteAllGuilds(guildStore, guildList)
guildList.Data = {}
guildStore:GlobalUpdateProfileAsync(
"guilds",
function(globalUpdates)
print("creating active update...")
globalUpdates:AddActiveUpdate(
{
updateType = "DeleteAll";
}
)
end
)
end
return module