MessagingService to trigger a Kick() to release an Update

Hey everyone!

I made a function called by MessagingService, by a command on chat (that only DevTeam can trigger) it will call all running servers in game, to show a GUI saying that the game will get an Update, and after certain amount of time, it will kick all players to refresh the servers with the last build.

But, this “warn” in MessagingService documentation: “Delivery is best effort and not guaranteed. Make sure to architect your game so delivery failures are not critical”

– If it fails for a server, I dont think I have a way to know that, is there any?

– If there are hundreds of servers running at the same time?.. makes any difference on the amount of messages (Limitation per game topics?)

Any suggestion for a different approach instead of MessagingService?

1 Like

Well, first off;

Yeah, just go to your game and hit “refresh” on the servers tab. After waiting a little, just force close the remaining servers if you’re sure data will save.

Second, yes there is a different way but I’ve never actually tried it out before.
You can have a script constantly check for a value change in a certain data store key (like every 20 seconds so it doesn’t overload the server) The data change can be done by your dev team via a command or script or whatever. The downside is that when all servers are shut down and the deed is done, it will stay done until you manually go to studio and change the value for shutting down the server. I’ll provide an example so it makes more sense.

local DTS = game:GetService("DataStoreService")
local serverEventDS = DTS:GetDataStore("myDataStore","liveEvents")
local valueToKick = ("chickenwing")
local key = ("fridaynightfunkin")



while true do
	task.wait(15)
	local value = serverEventDS:GetAsync(key)
	if value == valueToKick then
		-- get children of players and smite them into oblivion.. after showing a gui or something of course
	else
		print("no oblivion :(")
	end
end

so while thats the server script that waits until the value is changed

the other script that handles the value change will look something like this:

local DTS = game:GetService("DataStoreService")
local serverEventDS = DTS:GetDataStore("myDataStore","liveEvents")
local valueToKick = ("chickenwing")
local key = ("fridaynightfunkin")
local part = Instance.new("Part")
local players = game:GetService('Players')
local valueToKick = ("chickenwing")

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player1 = players:GetPlayerFromCharacter(hit.Parent)
		if player1.UserId == YOURID then
			serverEventDS:SetAsync(key,valueToKick)
			--then wait like 20-ish seconds
		end
	end
end)

I understand the flaws in my code I just whipped something up quick, I suggest if you do go down with this to store your values and key in a module for easier access. However, since messagingService is very scary I would like to try this sometime as well. Apologies if I couldn’t help.

1 Like

Thats a good idea, just using a datastore, changing a value from any server or studio, and all servers constantly checking that datastore in order to warn players and kick them. Then manually change the value back to allow players to play.

I was thinking on the same approach using MemoryStoreService too.

Another thing Im not sure, is, once all players in a server got kicked out, Im handling new incoming players by an instant kick unless server totally did shutdown, but, if new incoming players never stop to joining the server, even if they get instant kick, does the server really shutdown?
I dont like to manually shutdown servers from the website, I would prefer never shutdown from there, and just kick all players in all servers, so that server gets totally empty and new incoming players reach the last build of the game. Specially cause manually shutingdown servers could cause data not saved… But maybe, after the kick function happens, I could shutdown all servers I guess, without the risk of dataloss, cause new incoming players gets instant kick and datastores are never readed or written for them.

Thank you so much for your reply, its very helpful!

1 Like

I understand your worries, and here’s the solution to most of it. In here, roblox states that the most secure way is to shut down the server manually. However, your worries of data loss is valid, and that’s where BindToClose comes in. You can bind a function, in this case getting all players and running a save data function, when the server is going to close. This eliminates the problem of players joining and getting instant kicked and also limits data loss. But this means you still have to shut down from the developer menu after changing the datastore value and warning players. Still, everything said before works fine, but I thought i’d mention this.
image

1 Like

Thank you!
I was using BindToClose many times but only when working in Studio so I get all the prints when player (me) closing game, in order to check everything is saved.
Probably Im using BindToClose in a wrong way, as you stated, I could use it to run a for loop to save everyone’s data.

Then maybe my approach should be: Handling the Update Warning with timer by the Datastore check, kick all players when timer runs out, set the autoKicker on playerAdded after that, (being sure the BindToClose saves the data of players if that data exist) manually shutdown all servers from website. Or I should forget about the kicking? and just manually shutdown all servers from website when the timer runs out cause the BindToClose is saving the data?

1 Like

Sorry about the late response. You can do whatever you think fits well, maybe even try different methods on different games. The best way to find out the most viable option is to see for yourself.

1 Like