Does a lot of calculating actually makes the game lag? Or am I using the wrong way to script?

So, I make fighting games, I’ve made like four of them now, but none of them is out, cause every one of them was lagging crazy after published. I used to thought it was the meshes, cuz I got loads of them on the edge of max vertices amounts. So the project I’m working on right now, I kept it easy on the VFXs, but now after it’s published, it’s still lagging, lead me to thinking it wasn’t the VFXs that was causing the issues. After I removed the “Damaging” script which controls and output and stuffs, the game runs a lot smoother than before, but games like Grand Piece Online, their combat mechanics are really complicated too, why don’t they run into the issues I’m having? Maybe I’m doing stuffs the wrong way? Please let me know if there’s any tips or ways that can potentially fix this issue.

More Infos on my scripts:
I run the whole “Damage” calculation on the server end, example, if the hitbox was touched, if the hit was a model, does it got humanoid and stuffs like these. The whole “Damage” function is like 1000 lines long. And the game is not even 10% done, I don’t even know how lag it will be if its done 100%.

Yes, complex and/or repetitive calculations with definitely cause lag. Even a poorly managed loop will cause lag.

In fact, the following code will each cause the game to crash entirely:

repeat until false
function crash()
	crash()
end
crash()

Adding delays in most cases will massively reduce lag. There’s more to it than that, but to answer your question, yes.

1 Like

Interesting, thanks alot of the answering, to make my decisions easier, so what I should do now, is to try and polish my scripts to reduce more calculating or adding delays?

I can’t really give you a straight answer as it would depend on the state of your scripts. If written correctly, there shouldn’t really be any points where it should cause any lag. But adding delays to loops is a quick patch.

Honestly, the scary part is, there’s no loops in my scripts, the basic of it is just a lot of spawn functions looking for parts, values, or animations, but maybe I just have to figure which part is removable or try to make it with less calculations, but thanks a lot for the reply though

A spawned function will act like simulated parallel operations. If used improperly, this can definitely create lag. Recursive functions are another cause of potential lag if not dealt with properly.