You can try to use datastore, an example is when the script is fully loaded on 1 server it sets its status as loaded
When the script tries to fire the JSON code it will request from datastores if the script is loaded already, if it is loaded then it will just return and void the rest of the code on other servers.
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Name")
local messageRate = 60 -- message every 60 seconds
while true do
-- get the current time
local osTime = os.time()
local success, value = pcall(dataStore.UpdateAsync, dataStore, function(value)
-- you dont need to always do this but the first time to use this key value will = nil
if value == nil then value = 0 end
-- if the datastore time has a lower deltatime then messageRate abort the UpdateAsync
if osTime - value < messageRate then return nil end
-- if the delta time is grater then messageRate then update the datastore to the current time
return osTime
end)
if the datastore update was successfull and the time was updated
if success and value ~= nil then
-- send a message to discord
end
-- wait some time before we check then datastore again must wait at least 6 seconds
task.wait(10)
end
Can you make the script to just make one server Value true? (game.ServerScriptService.Script.messagingEnabled.Value = True) The messaging gets handled by a countdown script. It should activate the messaging script if the server value is true. So the data store should make a value true in only 1 server.
the code in my previous message will make all servers work as a team to message discord every 60 seconds (discord will only receive 1 massage every 60 seconds)
the code below will make 1 server do all the work and that will be the only server that messages discord (discord will only receive 1 massage every 60 seconds)
if the 1 server shuts down then another random server will take the place of the first server
local memoryStoreService = game:GetService("MemoryStoreService")
local sortedMap = memoryStoreService:GetSortedMap("SortedMap1")
local messageRate = 60 -- message every 60 seconds
while true do
local success, value = pcall(sortedMap.GetAsync, sortedMap, "Key")
if success == true then
if value == nil or value == game.JobId then
local success, value = pcall(sortedMap.SetAsync, sortedMap, "Key", game.JobId, messageRate + 1)
-- send a message to discord
end
end
task.wait(messageRate)
end
out of the 2 methods i sent you i like the first one better it feels more robust