Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't my game update script working properly?

Asked by 4 years ago
Edited 4 years ago

So I have a script that checks to see if the game is updated then warns players and kicks everyone. The problem is that EVERY time I join (In studio, IDK about in game), it says that the game was updated. My script:

local DSS = game:GetService("DataStoreService")
local lastUpdated = DSS:GetDataStore("LastUpdated")

local function CheckForUpdate()
    if game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId).Updated ~= lastUpdated:GetAsync("LastUpdated") then
        lastUpdated:SetAsync(game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId).Updated)
        status.Value = "The game has been updated!"
        for i = 10, 0, -1 do
            seconds.Value = i
            wait(1)
        end

        for i, player in pairs(game.Players:GetPlayers()) do
            player:Kick("The game has been updated! Please wait a minute, then join a new server.")
        end

    end
end

EDIT: It gives me an error on line 6: Argument 2 missing or nil.

2 answers

Log in to vote
3
Answered by 4 years ago

Not sure about that one, but I created a different version that works. I've tested in live servers.

local previousVersion = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId).Updated --// This will get the first version of the game when it starts open

game.Players.PlayerAdded:Connect(function(player) --// Starts running when a player joins.
    while wait(1) do --// Will always loop through the check, every 1 second. (Reduces memory use)
        local newVersion = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId).Updated --// Always checks for an updated version
        if newVersion ~= previousVersion then --// Checks if the game has been updated
            for _,player in pairs(game:GetService("Players"):GetChildren()) do
                player:Kick(game.Name.." Has Been Updated!") --// Kicks all the players telling them the game has been updated!
            end
        end
    end
end)

In my opinion, I don't think you need DataStore for game updates. You just need the first version of the current server when it first opens, and then do a loop checking if the game has been updated.

Hope this helped! If this is what you're looking for, let me know by selecting this as an answer!

Ad
Log in to vote
0
Answered by 4 years ago

I recommend using killerbrenden's script, but here's why your script isn't working:

  • The error occurs on line 6, meaning that the current version is never being stored in the data stores
  • The problem with line 6 is that you haven't specified that the key is "LastUpdated"
  • This script will only update new servers (which don't need updating), not old ones. If you wanted to use data stores here (but I still recommend killerbrenden's script), you'd want one if to take care of whether to update the data store or not, and then you'd have a loop to see if any other server has updated the data store since you last checked it. If so, then the version has changed.

Answer this question