Intense Lag While Moving

My game is very small but still lags down to about 20fps when the character walks. The game has afew models and about 15 scripts, I am using RenderStepped on my local scripts to try and avoid lag. The map is already so small and I am woried that when the game expands it will be unplayable even on top end devices.

Can anyone give my a tip on how I can reduce the lag. I can’t link the game as the project is supposed to be going secret. I would love to hear advice from people that have dealt with this in the past.

Here is the entire map so far

Thanks!

3 Likes

what game is it first, i wanna see if its a you problem or an actual lag problem

1 Like

The building in your map more than likely isn’t causing the issue since there’s not a lot there, so it definitely shouldn’t be memory intensive.

I’d recommend looking through your scripts since, to me, only the scripts could be causing the issue. You could move each script over to another place individually for you to test them, which might help you identify what’s causing the issues more efficiently. That’s all I can suggest because I’m not a scripter.

3 Likes

okay but im confused as to how text in a virtual script lags a game, if you mean the actions that it makes the objects do then that makes sense.

1 Like

To the best of my knowledge, loops (particularly while loops) and memory intensive processes can cause issues with performance. There’s likely other causes which arise from scripts alone but, as I said, I’m not a scripter.

2 Likes

Ohh so you think it’s something to do with the memory, yeah tbh i’m not a scripter either but you could be right

1 Like

Thus us hyst tge test game but in this place there are gates you can interact with, currently one npc that just walks around a little area and a zone you can go in that displays a gui.

I can’t share a link as I don’t want ot reveal too much of the game

1 Like

Not really sure in this case.

Do your scripts have loops? And if so, how many?

Some of your scripts could be near script exhaustion, this causes a bunch of server lag.

1 Like

I ahve afew “while wait()” loops in there on the server but on the Client I have mainly switched to “RenderStepped”

They could be near exhaustion though so I will check that

1 Like

What are you running on the renderstepped events?

I highly recommend making those as meshes. That might reduce the lag.

The lag isn’t from a map that small. It’s a code issue.

You should only be using renderstepped for functions relating to the players character or camera. (All code in your renderstepped functions have to run before the next frame will be rendered, causing huge performance issues.)
Heartbeat should be used for everything else.

1 Like

I only said that, just because this is a building support topic.

I replaced the Renderstepped with heartbeat and it made the lag appear at a later time but the game still became laggy after a short while.

It’s kind of both but at first i thought it might be building

Alright. What exactly are you using heartbeat for?

Checking “mouse.target” and another one in a different script changing some values

How many RenderStepped loops are you running?
What are these loops doing?
Please provide the code inside of the loops.

If you’re binding slow code to renderstepped - that’s a red flag as it has to run that code before the scene renders. Try switching to Heartbeat and get back to me :grin: - happy new years!