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
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
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.