How to make a game lag less

I dont know how to use the micro profiler. How do you use it? What is it even for?

You could read this article

1 Like

Is this in studio? Try using it in game too, and lowering your graphics quality.

3 Likes

Ive tested the gun with microprofiler and it appears to have these large orange bars mostly when equiping and unequipping the gun

The runJob is what appears to have the most calls
image

However i found the guns Local script and it seems to be getting called 29 times when equipping.

Im not sure if this means anything or what runJob even does

Can you show the code which equips/unequips the gun?

Yeah, i recently added some checkers to stop a idle animation bug

Equip Script:


firearm.Equipped:Connect(function()
	
	IdleAnim:Stop()
	
	Mouse.Icon = MouseIcon
	
	
	Equipped = true	
	
	if character.Humanoid then
		
		IdleAnim:Stop()
		
		task.wait(.05)
		
		EquipAnim:Play()
		
		task.wait(0.9)
		
		EquipAnim:Stop()
		
		if Equipped == true then
		Idling = true
		
		IdleAnim.Looped = true
		
		IdleAnim:Play()
		
		else
			
			Idling = false
			Equipped = false
			IdleAnim:Stop()
			
			end	
			
		if Jammed == true then
			
			game.Players.LocalPlayer.PlayerGui.GunHUD.MAG.ThisGunJammedBro.Visible = true
			
		else

		end
		
	else
		warn("No humanoid?")
		
	end
	
end)

Unequip script:

firearm.Unequipped:Connect(function()
	
	Mouse.Icon = ""
	
	if IdleAnim then
		
		IdleAnim:Stop()
		
		UnequipAnim:Play()
		
		Idling = false
		
		Equipped = false
		
	end
	
end)


1 Like

Honestly, I don’t see any issue with the scripts

1 Like

Mabye it could be runJob? I saw that get called the most

1 Like

Useful tips for debugging when you have no clue what causes issues:

  • use print statements to identify what code is ran
  • Progressively disable more and more (comment out) until the issue is resolved

The second point is probably the best for your usecase. You already found out it’s when someone does, or shoots. You should start from those functions and keep disabling more and more features until the issue is fixed.

1 Like

So i decided to delete everything in my game, and my memory still ran at 1.8KMB in studio when everything apart from baseplate is deleted

Try optimizing the code that triggers when a bullet hits a player.

1 Like

But how can i optimise this?? Ive already used task.wait() since it’s more reliable

1 Like

Removing bloaty functions caching some things maybe. Hard to say without having the code to pinpoint the problem.

Memory doesn’t mean much. Especially memory in studio.
You should only investigate memory if your players experience crashes in game

Going from assumptions is useless, as memory is dependent on the device. If the device supports it, Roblox will use more memory.

Are you actually having performance issues? Or are you just going off the assumption of “memory is too high”?

So is it just my device then? I haven’t had any crashes at all when testing.

Idk if this is a troll post or something but just use the profiling tools and take care of everything that takes the most resources?

Troll post? There’s been a full on discussion about how i could fix my issue. I’m not sure where u got the idea of a troll post from…

  1. Disconnect unused connections, and use connection:Once(function) if possible.
  2. Use the task library.
  3. Use Run service connections if possible, and NEVER do this:
while true do
    runService.Heartbeat:Wait()
end
1 Like

I’ve never used these before, What does it do?

1 Like
  1. A connection is when you do this:
    SomeService.Signal:Connect(function). If you leave unnecessary connections open it is considered a memory leak. Example of disconnecting a connection:
local playerAddedConnection
playerAddedConnection = players.PlayerAdded:Connect(function()
    -- Some code
end)

playerAddedConnection:Disconnect()

When you disconnect a connection, it will not longer fire (if that wasn’t obvious already)
Once is like Connect but it disconnects immediately after firing do you don’t have to do all the goofy variable stuff.

  1. The task library is a relatively new library implemented by Roblox that serves as a better replacement of wait(), delay(), spawn(), and more.
    For example, you will almost always want to replace wait() with task.wait().
    And for small performance improvements, you can use task.defer() instead of task.spawn() when you don’t care about the coroutine resuming immediately.

  2. RunService connections would look like this:

local runService = game:GetService("RunService")

runService.Heartbeat:Connect(function()
    -- Code here
end)

These connections fire every frame which makes them a viable replacement for while true do imo.
There is also RunService.RenderStepped and RunService.Stepped. There are differences to these signals which I would take a look at in the RunService documentation.
For better performance, use .Heartbeat whenever possible.

1 Like