local MessagingService = game:GetService("MessagingService")
local MESSAGING_TOPIC_SERVER_START = "StartedServerInstance"
local MESSAGING_TOPIC_SERVER_RESPONSE = "ResponseServerInstance"
local GROUP_CONTROL = "Control"
local GROUP_TEST = "Test"
local cachedServers = {
Test = 0,
Control = 0,
}
local testGroup = nil
MessagingService:SubscribeAsync(MESSAGING_TOPIC_SERVER_START, function(message)
print("When this is fired, it means a new server started and it wants to check how many instances are there")
MessagingService:PublishAsync(MESSAGING_TOPIC_SERVER_RESPONSE, testGroup)
end)
MessagingService:SubscribeAsync(MESSAGING_TOPIC_SERVER_RESPONSE, function(message)
print("###########################")
if message.Data then
cachedServers[message.Data] += 1
end
print("###########################")
end)
MessagingService:PublishAsync(MESSAGING_TOPIC_SERVER_START, nil)
-- Process what kind of server instance this will be
task.delay(5, function()
if testGroup then
local serversCount = cachedServers[GROUP_TEST] + cachedServers[GROUP_CONTROL]
local testPercentage = (cachedServers[GROUP_TEST] / serversCount) * 100
local controlPercentage = (cachedServers[GROUP_CONTROL] / serversCount) * 100
if testPercentage <= 50 then
testGroup = GROUP_TEST
end
return
end
print("If no response from servers them randomly assign a group")
local random = math.random(1, 10)
print("Assuming this is a 50% chance of being control")
if random <= 5 then
testGroup = GROUP_CONTROL
else
testGroup = GROUP_TEST
end
task.wait(1)
print(cachedServers)
end)