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

How to make a optimization system at my game?

Asked by 4 years ago

Ello,i m trying to make a script that can reduce lag(fps and ping) at my game.I dont know how start it.

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

It's more of a question of "how do I script my game to run better"?

One thing I see way too often are unnecessary loops:

  • while true do
  • while wait(1) do
  • repeat until

Try to use while loops only if you have to. Most things can be triggered by calling functions / using events (built in roblox events or your own) so you don't have to be constantly waiting for something to happen.

I'll give you an example, let's say I wanted to have some code that runs when my brick in game is transparent:

I could do this:

while(true)do
    wait()
    if(game.Workspace.Part.Transparency == 0.5)then
        --DO SOMETHING!!
    end
end

but that would keep running the loop as long as the script is active/in the game. Doesn't seem too bad, but when you have a bunch of loops like this, it'll lag up your game.

You could instead do this which only runs when the transparency changes:

game.Workspace.Part:GetPropertyChanged("Transparency"):Connect(function(transparency)
    if(transparency == 0.5)then
        --DO SOMETHING!!!
    end
end)

You should make sure you're making the least amount of comparisons as possible.

The first example above runs more than the second example, making a lot more comparisons. It'll lag up the server more than the second example.

This doesn't just go for loops, but in your algorithms as well. Spend some time thinking about an efficient solution. Your first solution to a problem is usually never the best one.

Building a big game and having a lot of animations lags down your game as well. If you want to get a bit more advanced, you could make some sort of system that only animations/the map when they're within a certain distance from you.

0
Hi, you've been online since I last posted, but you seem to not have the question answered. Do you still need this answer to be answered or does the code above work? royaltoe 5144 — 4y
0
hi,my friend said to reduce server memory used,idk how to do this. iBeatuEZ 27 — 4y
0
hi if youre still online ill rely in a sec royaltoe 5144 — 4y
0
he just means that you should try to have less code running on the server (make your scripts run less). usually there's ways to write a program without having to use while loops. review your code and see if you're using while loops anywhere inappropriately. royaltoe 5144 — 4y
View all comments (2 more)
0
ill edit my answer to give an example royaltoe 5144 — 4y
0
edited royaltoe 5144 — 4y
Ad

Answer this question