From 65a5bab6236f5fe52b3c44fe4ed5d9b1c58a742f Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Thu, 14 Apr 2022 14:50:27 +0000 Subject: [PATCH] perf(points): use interval for on-frame thread --- imports/points/client.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/imports/points/client.lua b/imports/points/client.lua index 596b5ac..9c553fa 100644 --- a/imports/points/client.lua +++ b/imports/points/client.lua @@ -6,6 +6,7 @@ end local nearby = {} local closest +local tick CreateThread(function() while true do @@ -38,14 +39,17 @@ CreateThread(function() point.currentDistance = nil end end - end -end) -CreateThread(function() - while true do - Wait(0) - for i = 1, #nearby do - nearby[i]:nearby() + if not tick then + if #nearby > 0 then + tick = SetInterval(function() + for i = 1, #nearby do + nearby[i]:nearby() + end + end) + end + elseif #nearby == 0 then + ClearInterval(tick) end end end)