Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Automatic server shutdown when new version not working... Please help???

I'm trying to make a automatic shutdown when every there is a new version and this is the error I'm getting:

Stack Begin Workspace.Script:8: attempt to preform arithmetic on local 'len' (a string value) 'Workspace.Script', Line 8 - global Getversion 'Workspace.Script', Line 12 Stack End

Does anyone have any idea on what's going on??

mps = game:GetService('MarketplaceService')
_Version = nil

function GetVersion()
    local str = mps:GetProductInfo(game.PlaceId).Description
    print(str)
    local len = tostring(str:find('_Version'))
    return str.sub(len, len+5)
end

while wait(120) do
    local new w= GetVersion()
    if _Version then
        if _Version ~= new then
            local msg = Instance.new('Message', workspace)
            for i = 60,1 do
                msg.Text = 'The game is shutting down for an update in: ['..i..']'
            end
            while wait() do
                for i,v in pairs(game.Players:GetChildren()) do
                    if v:IsA'Player' then
                        v:Kick()
                    end
                end
            end
        end
    end
    _Version = new
end

1 answer

✓ Accepted answer

string.find will return nil if the pattern is not found so you should also handle this scenario. When it is found the start and end points are returned as integers.

On line 7 you have:-

local len = tostring(str:find('_Version'))

This will returns two numbers or nil, you then convert this to a string. You then have:-

return str.sub(len, len+5)

As len is now a string and not an integer you will get an error as sub requires its parameters to be integers.

Here is a quick example of how to use it:-

local msg  = 'aaa _Version:- 1.0'
local startStr, endStr = msg:find('_Version%:%-')
msg = msg:sub(endStr+2) -- as we had whitespace
print(msg)

I hope this helps.

This discussion is preserved as it was. New answers, comments, and votes are closed.