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

what exactly causes major lag in games?

Asked by 5 years ago
Edited 5 years ago

not sure how close this is to counting as a "scripting question" but its relevant

my question is: what actions cause major lag?

for example, (on my computer and probably most)

  • instancing a new part into the workspace every 0.01 second will definetly cause lag over time

  • instancing 100000 parts at once will cause instant lag (crash)

  • print("hello") every 0.01 second does NOT cause lag (i assume because parts take up more data in memory)

so is there a specific "condition" that must be met in order to "cause lag" such as using lots of data? parts lag because they use up more data than print? (maybe i answered my question but id like to be sure)

lag can accumulate over time (like instancing too many parts). what else should be avoided to prevent lag over time?

also, is there a property under part that could make a large structure less laggy? i thought massless would lower the lag in a game i made with 1000 parts but it didnt. a "low settings" option?

thank you in advance

0
While true do has pretty heavy impact on performance Banned_Monte 18 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

When coding, here are some things that cause lag: 1. Loops 2. Excessive parts 3. Lots of unions. 4. Many moving objects 5. Many players 6. Coroutines

Now here are a few things you can do to prevent it from happening: 1. I believe SetNetworkOwner has some part in lag... 2. Use arrays and tables more often 3. Try to use only 2 loops in a game, unless you need to add more.. 4. Definitely put wait() in a loop to reduce lag. 5. Try using touched events instead of coroutines because those threads can kill while roblox coroutines don't kill threads.

I hope this helped, if this did, click the answer button, thanks

By unioning parts, it reduces parts into a single part in easy terms

Also there is a way where you can literally get rid of lag, by hiding the parts within a certain range. Although you would need to use 2 loop

while true do wait()
    for _, v in pairs(workspace:GetDescendants()) do
        if v:IsA("BasePart") then
            if (game.Players.LocalPlayer.Character.HumanoidRootPart.Position-v.Position).Magnitude < 100 then -- 100 is the distance away
                v.Transparency = 0
            else
                v.Transparency = 1
            end
        end
    end
end
0
thank you so much this 100% answered my question. i had no idea transparency could help with lag Spiritlotus 151 — 5y
0
For some reason it does c:, You are welcome greatneil80 2647 — 5y
Ad

Answer this question