attempt to perform arithmetic

This script keeps giving me a error, it works, but I want to get rid of the yellow errors when joining.

The error is:
gamemode\cl_init.lua:502] attempt to perform arithmetic on local ‘s’ (a string value)(Hook: HUDPaint)

The script is:

local s = LocalPlayer():GetNetworkedString(“cider_TimePlayed”); --How many total seconds do we have
local totalm = math.floor( s / 60 ); --How many total minutes do we have
local h = math.floor( totalm / 60 ); --How many total hours do we have
local m = totalm - h * 60; --Minutes left
s = s - totalm * 60; --Seconds left

table.insert( text, {“Time Played: “…h…”:”…m…":"…s…"", “gui/silkicons/table_edit”} );


You need to tostring s.

[lua]local s = tostring(LocalPlayer():GetNetworkedString(“cider_TimePlayed”));[/lua]


I tried both suggestions but it keeps giving the error.

Don’t know if %H or %I are bugged in gmod, but you could always do this:

local dt = tonumer( LocalPlayer( ):GetNWString( "cider_TimePlayed" ) ) or 0
table.insert( text, { "Time played: %H:%M:%S", -3600 + dt ), "gui/silkicons/table_edit" } )

On the demo site, %H and %I start at 1 rather than the cited zero in the documentation, so you have to offset an hour backwards ( hence -3600 ).

Don’t know if this will work correctly in gmod, but it does in a normal environment.

I tried your script, but it gives this error:
[@lua\includes\extensions\string.lua:33] bad argument #1 to ‘find’ (string expected, got nil)(Hook: HUDPaint)

Edit: I got rid of the error by placing [lua]or 0[/lua] on line 1

There is already and or 0 on the first line :psyduck:

On your script it is but I meant this:

[lua]local s = tonumber(LocalPlayer():GetNetworkedString(“cider_TimePlayed”)) or 0;[/lua]

That is what it was before.

Like I said, I haven’t had the chance to run this in gmod, but codepad gives a different result than the demo on

print( "%H:%M:%S", 1 ) )
print( ) )

Expected behavior should be printing “00:00:01” and then the date and time on the server.’s demo prints:

And then their local time

codepad prints 00:00:01

So the offset may or may not be needed depending on how gmod handles %H