Put
local ping = getPlayerPing(getLocalPlayer())
inside the render.
local screenW, screenH = guiGetScreenSize() -- you don't have to get the screen size inside the render function
local disappearTime = 10 -- seconds
--local ping = getPlayerPing(source)
function ping2()
if ping then
local ping = getPlayerPing(getLocalPlayer())
dxDrawText("Weapons disabled Ping+ 600 ("..ping..")", screenW * 0.0492, screenH * 0.9453, screenW * 0.2281, screenH * 0.9714, tocolor(254, 53, 53, 254), 1.00, "default-bold", "center", "top", false, false, false, false, false)
end
end
function handlePing2Render(state)
-- if you want the timer solution then just delete the --[[ and the ]] at the end and delete the code above
removeEventHandler("onClientRender",getRootElement(),ping2) -- add this so there won't be errors in debugscript about event is being already handled
addEventHandler("onClientRender",getRootElement(),ping2)
setTimer(function()
removeEventHandler("onClientRender",getRootElement(),ping2)
end, disappearTime*1000, 1)
end
addEvent("ping1", true)
addEventHandler("ping1", root, handlePing2Render)