Ello,i m trying to make a script that can reduce lag(fps and ping) at my game.I dont know how start it.
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:
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.