How can i fix the issue(read title)
Heres an example script of what i mean.
--Example local function getProp(obj, prop) local getPropVar = obj[prop] return getPropVar end local protectedCall = pcall while wait() do for i,v in next, game:GetDescendants() do local Transparency = protectedCall(function() getProp(v, "Tranparency") end) if Transparency then Tranparency = 1 end end end
Running this lags you.
Is there any way to reduce the lag or get rid of the lag?
Any help is appreciated.
local function getProp(obj, prop) local getPropVar = obj[prop] return getPropVar end local protectedCall = pcall while wait() do wait(0.001) -- Example for i,v in next, game:GetDescendants() do wait(0.01) -- Example local Transparency = protectedCall(function() getProp(v, "Tranparency") end) if Transparency then Tranparency = 1 end end end
So the issue with your "for loop" is that it is running without any restriction so you just need to add a wait(). It can be as small as wait(0.001) but if your script has no restriction it will just use as many resources as it can to go as fast as it can.
Hope I helped!