What are the factors that cause my Game becomes so Laggy?

Does running multiple scripts at the same time can cause lag?

3 Likes

That’s entirely dependent on the complexity of said scripts that are going to run multiple times. If I can ask, what’s the context?

It depends on what the scripts are doing. Howbeit usually no, as games are built to run using multiple Scripts or LocalScripts without the game lagging.

Has your game been lagging recently?

i got two while loop scripts on the server scripts

That might explain it. If you don’t use wait() or task.wait() within while loops, sometimes that can cause the game to crash or lag. Not directly the result, of using multiple scripts though.

Splitting code into multiple scripts and running it at the same time does not in itself reduce performance.
However, you may find it difficult having your scripts communicate with each other with a lot of code -
focus on the actual code and optimising it well.

Read what your code is doing and think whether it is doing it in an optimal way to increase performance.

4 Likes

my game is inspired like a DoomSpire game where the base were made of multiple parts and held by weld and it can be destroy by an explosion.

1 Like

Are you experiencing lag, when you test or play your game?

yes everytime me and my friend were close to the base that were made of multiple parts

Are all the parts anchored? Sometimes unanchored parts (especially having lots of them), can cause lag.

Collisions Can Cause Serious Lags.

its anchored and welded at first but when a certain condition is meet then it will turn into anchored = false and still welded.

I think it might just be because there are a lot of parts involved, and when they become unanchored they can cause some serious lag.

  1. When the certain condition is met, do they all unanchor at once or do only certain parts become unanchored?
  2. Do you and others experience the same lag?

even if the base are still anchored it cause some Lag every time i went close to.the Base

Can you show us the link of the game, so we can test the lag out too?

On another note, you should maybe change the description & title of the topic, since you originally asked a question, but now the topic has become a problem. Either that or maybe create a new topic for the problem.

Hi herbz this is the link of my game by the way

i suspected that this script made my game so laggy i think

db = false
while true do
	wait(5)
	local Base = game.Workspace:WaitForChild("Base")
	local BlueCube = game.Workspace:WaitForChild("BlueCube")
	local PurpleCube = game.Workspace:WaitForChild("PurpleCube")
	BlueCube.Touched:Connect(function(hit)
		if hit:IsA("BasePart") and hit.Name == "PurpleGoal" and hit.BrickColor == BrickColor.new("Pastel violet") then
			for i,v in pairs(Base:GetDescendants()) do
				if v:IsA("BasePart") and v.Name == "-Purple" or v:IsA("SpawnLocation") and v.BrickColor == BrickColor.new("Pastel violet") then
					v.Anchored = false
					hit.Transparency = 1
					BlueCube:Destroy()
				end
			end
		elseif hit.Name == "Water" and hit.Transparency == 1 then
			BlueCube.Position = Vector3.new(-54.5, 4.559, 51.5)
			BlueCube.Orientation = Vector3.new(0,0,0)
			BlueCube.Anchored = true
			wait(3)
			BlueCube.Position = Vector3.new(-54.5, 4.559, 51.5)
			BlueCube.Orientation = Vector3.new(0,0,0)
			BlueCube.Anchored = false
		end
	end)
-------------------------------------------------------------------------------------------------	
	PurpleCube.Touched:Connect(function(hit)
		if hit:IsA("BasePart") and hit.Name == "BlueGoal" and hit.BrickColor == BrickColor.new("Bright blue") then
			for i,v in pairs(Base:GetDescendants()) do
				if v:IsA("BasePart") and v.Name == "-Blue" or v:IsA("SpawnLocation") and v.BrickColor == BrickColor.new("Bright blue") then
					v.Anchored = false
					hit.Transparency = 1
					PurpleCube:Destroy()
				end
			end
		elseif hit.Name == "Water" and hit.Transparency == 1 then
			PurpleCube.Position = Vector3.new(-483.5, 4.561, 19.5)
			PurpleCube.Orientation = Vector3.new(0,0,0)
			PurpleCube.Anchored = true
			wait(3)
			PurpleCube.Position = Vector3.new(-483.5, 4.561, 19.5)
			PurpleCube.Orientation = Vector3.new(0,0,0)
			PurpleCube.Anchored = false
		end
	end)
	-------------------------------------------------------------------------------------
	local Dirt = game.Workspace:WaitForChild("Dirt")
	local SolidDirt = game.Workspace:WaitForChild("SolidDirt")
	for i,v in pairs(Dirt:GetChildren()) do
		if v:IsA("BasePart") then
			v.Touched:Connect(function(hit)
				if hit.Name == "HitBox" and not db and hit.Size == Vector3.new(0.31, 0.512, 0.273) then
					db = true
					v.Transparency = v.Transparency + 0.2
					wait(0.1)
					db = false
				elseif hit.Name == "HitBox2" and not db and  hit.Size == Vector3.new(0.31, 0.512, 0.273) then
					db = true
					v.Transparency = v.Transparency + 1
					wait(0.1)
					db = false
				end
			end)
		end
	end
	for i,v in pairs(SolidDirt:GetChildren()) do
		if v:IsA("BasePart") then
			v.Touched:Connect(function(hit)
				if hit.Name == "HitBox2" and not db and  hit.Size == Vector3.new(0.31, 0.512, 0.273) then
					db = true
					v.Transparency = v.Transparency + 0.2
					wait(0.1)
					db = false
				end
			end)
		end
	end
end

1 Like

I tried playing the game and everything worked fine for me when there was nobody else on the game. However, when there were three players on, that’s when the intermittent lag started.

Might just be down to Game size possibly, but not sure. If not, try disabling or removing the script and see if it fixes the problem (not that it would be a permanent fix though).

It works smooth when we play it with my friend on the same computer shop but after 20mins its starts become so laggy. i Dont know if the our computer was the issue or game. Heres a short viedo clip

robloxapp-20220830-2030537.wmv (2.0 MB)

1 Like