However, i was wondering. How do i get the LATEST VERSION
I want to create an auto update feature. Where when a new update comes out, each server checks if they are on the correct version, if they are not, there game shutsdown.
local MessagingService = game:getService("MessagingService")
local DataStoreService = game:GetService("DataStoreService")
local PlaceVersionDS = DataStoreService:GetDataStore("PlaceVersion")
local PlaceVersion = game.PlaceVersion
MessagingService:SubscribeAsync("PlaceVersion", function(message)
if message.Data > PlaceVersion then
for i,v in pairs(game.Players:GetPlayers()) do
v:Kick("Place version out of date")
end
end
end)
local success, dataVersion = pcall(function()
return PlaceVersionDS:GetAsync("PlaceVersion")
end)
if success then
if dataVersion then
if dataVersion < PlaceVersion then
PlaceVersionDS:SetAsync("PlaceVersion", PlaceVersion)
MessagingService:PublishAsync("PlaceVersion", PlaceVersion)
end
else
PlaceVersionDS:SetAsync("PlaceVersion", PlaceVersion)
end
end
Is your API Service enabled? I haven’t learned much about datastores, it I know you have to have api services to use them. Correct me if I’m wrong.
(sorry about my grammar errors, this autocorrect sucks lol)
It works by reading from a datastore key and automatically kicks out all players if the version is higher than the current one.
I would suggest you make a gui that tells players that an update is coming out in x seconds instead of kicking them out and updating the place, because that functionality is already done through the migrate server mechanic.
@cjjdawg The difference between what he wants and what the Migrate to Latest Update feature does is that he wants to automatically shutdown old servers rather than having to click the “Migrate to Latest Update” button every time he updates the game.
@TheEmeraIdDev I tested it in a live server and it worked for me. It works by saving the value of the most recent PlaceVersion in a DataStore. Then whenever a new server is created, it shuts down any existing servers with PlaceVersions less than that server’s PlaceVersion (aka old servers).
Make a place with a maximum server size of 1. Then join the server, update the game in studio to change the place version, then tell a friend to join a new server. Once they join, you should be kicked from your server.
You need two live servers to test it. You don’t need a while statement as MessagingService automatically receives a message to shutdown any time a server with a new PlaceVersion is created.
If you want to test it out, make the game’s max players to 1 and test it on your main account on the first server, then place your alternative or have a friend on the second one.