Guns keep freezing the game

So i’m trying to make an FPS game maybe something like Rivals. Theres no maps yet, not a lobby, because im stuck with the guns.

The rifles keep freezing the client, the normal one freezes my friend’s game, but the burst rifle even froze my game.

I searched for solutions, tried optimizing it in some ways but it didn’t help
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I’m sure a single script won’t be enough, so i will provide a file with the correct setup:

RifleSetup.rbxl (100.4 KB)

(Note: this is my second ever post, so thats why its so short, i didnt get skilled enough to make good posts)

1 Like

A lot of times people learning mention that running a section of code freezes the game.
Have a look at things like loops that don’t have a task.wait() in them. If they don’t then the code gets stuck doing just that loop with very little chance of it breaking out of it and continuing.

1 Like

Here are some things that might be causing that,
image
The line which i’ve screenshotted might be looping over and over again at max speed, meaning it will crash your game, just adding a task.wait() to that line will be fixing it, and it will stop the lag.
image

Second thing i’ve seen is; Why are you not using Raycasting for your gun(s) ? It’s a much better and efficient way to make a properly working gun.

5 Likes

That’s only for the normal rifle, what about the burst rifle?

1 Like

You do the exact same thing.


Whenever you engage a loop, please always make sure to have atleast a wait function there, otherwise it’ll loop as fast as your computer can pushing it at it’s limits and ultimately crashing it/causing extreme lag.

1 Like

Thanks, it actually helped! And i also made it raycast now.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.