Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

While looping a for loop lags player?

Asked by 3 years ago
Edited 3 years ago

Heres the script:


--Example local function getProp(obj, prop) local getPropVar = obj[prop] return getPropVar end while wait() do for i,v in next, game:GetDescendants() do local Transparency = pcall(function() getProp(v, "Tranparency") end) --The part that lags (from what im thinking) if Transparency then Tranparency = 1 end end end

Its pretty simple. Incase if you dont understand, its supposed to get every object in game and then check if the object has Transparency property. And if it does, it sets it to 1. So the problem is pcall(from what im guessing) since it lags the server. Ive tried adding a wait() to the for loop. it works but it makes the loop really really slow cause of pcall. It cuts it and then plays it back after a few seconds and then cuts it again.

Is there any fix to this?

0
you should use ipairs and pairs instead of next() MarkedTomato 810 — 3y
0
This makes the game lag because of the pcall you're creating a function everytime. MarkedTomato 810 — 3y
0
also line 13 you spelt "transparency" wrong MarkedTomato 810 — 3y
0
MarkedTomato is there anyway to fix it? RemsFriend -24 — 3y

Answer this question