Getting Time left minus curtime problem

Ok im trying to add on to an addon I made called sim helper pretty self-explanatory on what it does but I want to make the delay timer either go on a hud hook which iv tried to do and gotten errors or have the chat command I made say [Sim Helper] There is <TIMELEFT> left. ps not how Iv been doing. Ill show you the code and errors I get. Iv tried doing this to get the time left


local timeleft = string.ToMinutesSeconds( timetimerles - CurTime() )

but this causes errors with arthimatics

error



[ERROR] addons/sim_helper_by_snowa/lua/autorun/client/cl_netcode_recive.lua:83: attempt to concatenate local 'timetimerles' (a nil value)
  1. func - addons/sim_helper_by_snowa/lua/autorun/client/cl_netcode_recive.lua:83
   2. unknown - lua/includes/extensions/net.lua:32


[ERROR] addons/sim_helper_by_snowa/lua/autorun/client/cl_netcode_recive.lua:81: attempt to perform arithmetic on local 'timetimerles' (a nil value)
  1. func - addons/sim_helper_by_snowa/lua/autorun/client/cl_netcode_recive.lua:81
   2. unknown - lua/includes/extensions/net.lua:32


client side


net.Receive( 'sendSHT', function()
local timetimerles = timer.TimeLeft("delaytimer")
--local timeleft = string.ToMinutesSeconds( timetimerles - CurTime() )
print(timetimerles)
chat.AddText(noticecolor, '[Sim Helper] ', announcolor, 'There is '..timetimerles.." left!")

    end)

server side


hook.Add("PlayerSay", "sht", function(ply, text, public)
	if (string.sub(text, 1, 4) == "!sht") then
	        net.Start("sendSHT")
	         net.Send(ply)

			return ""
        end
end)

init


local delaytimerthing = 600

local shouldOccur = true

function ENT:AcceptInput(name, activator, caller)
	if name == "Use" and caller:IsPlayer() then

		if shouldOccur then

		net.Start("spawn_npcs")
		net.Send( activator )
		shouldOccur = false

		net.Start( 'colorchatmsg' )
		net.Broadcast()
		net.Start( 'startthe3d' )
		net.Broadcast()
 
timer.Create("delaytimer", delaytimerthing, 0, function()
	shouldOccur = true end)
		end
	end
end

errors


nil

[ERROR] addons/sim_helper_by_snowa/lua/autorun/client/cl_netcode_recive.lua:83: attempt to concatenate local 'timetimerles' (a nil value)
  1. func - addons/sim_helper_by_snowa/lua/autorun/client/cl_netcode_recive.lua:83
   2. unknown - lua/includes/extensions/net.lua:32



[lua]
local timetimerles = timer.TimeLeft(“delaytimer”)
[/lua]

is nil because you are trying to get the time left of a timer created serverside. When sending the net message from the server to the client you should write the time’s time left so the client can read it.

Ok so other than that everything checks out? Also I was thinking I needed to network it up but wasnt sure thanks tho I will try that.

[editline]22nd October 2017[/editline]

Hm, same error, I feel like I’m on the right track tho, I just don’t know what I’m doing wrong. I was never good at math.

init


local delaytimerthing = 600

local shouldOccur = true

function ENT:AcceptInput(name, activator, caller)
	if name == "Use" and caller:IsPlayer() then

		if shouldOccur then

		net.Start("spawn_npcs")
		net.Send( activator )
		shouldOccur = false

		net.Start( 'colorchatmsg' )
		net.Broadcast()
		net.Start( 'startthe3d' )
		net.Broadcast()
	--net.WriteString(timer.TimeLeft('delaytime'))
timer.Create("delaytimer", delaytimerthing, 0, function()
	shouldOccur = true end)
	net.WriteString(timer.TimeLeft('delaytime'))
		end
	end
end

client


net.Receive( 'sendSHT', function()
local timerlefts = net.ReadString()
local timeleft = string.ToMinutesSeconds( timerlefts - CurTime() )
print(timeleft)
chat.AddText(noticecolor, '[Sim Helper] ', announcolor, 'There is '..timeleft.." minutes left!")

    end)

error



[ERROR] addons/sim_helper_by_snowa/lua/autorun/client/cl_netcode_recive.lua:79: attempt to perform arithmetic on local 'timerlefts' (a string value)
  1. func - addons/sim_helper_by_snowa/lua/autorun/client/cl_netcode_recive.lua:79
   2. unknown - lua/includes/extensions/net.lua:32


Your problem is you’re performing arithmetic on a String value here:


local timeleft = string.ToMinutesSeconds( **timerlefts** - CurTime() )

When timerlefts is defined as a String here:


local timerlefts = net.ReadString()

[editline]Edited: [/editline]

For a bit more help, AFAIK (I haven’t played with GMOD LUA in a bit), you can use tonumber to parse “timerlefts” into an int, and then perform the arithmetic on your delay from there.

Im still getting a nil value. Im thinking my networking has holes I’m honestly not sure. Would it be eaiser to make the AcceptInput start a network and then sends it to the server and then in a server file send the string idk.

EDIT: Im gonna sleep on it, no one ninja me lol that was a joke please help.