Constant Game Lag

Hello! I’m currently looking to fix the lag that is within my game.

I have had my 3D-Modelers reduce all of our triangle counts and we are currently still experiencing lag. I have come to think that it is a memory leak or some other type of script lag.

MicroProfiler

I don’t really think it takes a genius to say that this doesn’t look good. (Of course I’m not a genius so I’m not sure what this means)

Memory

18,000 PING!?!?

1 Like

For future reference, the ‘lag’ caused by tri-counts and the like affect FPS and client-sided things. Having more can increase server-sided memory, I think, but not with the same devastating effect seen on the client (1 FPS lol) :slightly_smiling_face:

Ping lag is unrelated, as far as I know, but looking at this thread could change that: https://devforum.roblox.com/t/why-is-roblox-getting-so-laggy/4300

So it could be that you are simply doing way too much.

I’m no expert on this so /shrug

1 Like

I did some trial and error testing- it seems to me that our current system to apply user morphs lags. I don’t believe that this is the only cause though. I’ll continue testing.

I’ll also be willing to pay substantial amounts of money for help on this.

I really didn’t find much use for that thread sadly. :frowning:

1 Like

You could be having issues with garbage collection.

How do you apply the morphs, and listen for stuff and all of that?

Maybe provide the code if possible so I (and others) can take a look.

Whenever a player joins this function would be called…

local function MorphUser(User,Team,Class,Morph,name)
local MorphRoot = Morphs[Team][Class]:WaitForChild(Morph)					
for _,v in pairs(User.Character:GetChildren()) do
	if v.Name == name then
		v:Destroy()
	end
end
local UserMorph = MorphRoot:Clone()
UserMorph.Parent = User.Character
UserMorph.Name = name
if UserMorph:FindFirstChild('Shirt') then
	if User.Character:FindFirstChild('Shirt') then
		User.Character.Shirt:remove()
		UserMorph.Shirt.Parent = User.Character
	end
end
if UserMorph:FindFirstChild('Pants') then
	if User.Character:FindFirstChild('Pants') then
		User.Character.Pants:remove()
		UserMorph.Pants.Parent = User.Character
	end
end
for _,u in ipairs(UserMorph:GetChildren()) do
	if u.Name ~= 'Shirt' and u.Name ~= 'Pants' then
		--u.Middle.Transparency = 1
		for _,p in ipairs(u:GetChildren()) do
			if p:IsA("BasePart") then
			 	local W = Instance.new("Weld",u.Middle)
				W.Part0 = u.Middle
				W.Part1 = p
				local CJ = CFrame.new(u.Middle.Position)
				local C0 = u.Middle.CFrame:inverse()*CJ
				local C1 = p.CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
			end
			local Y = Instance.new("Weld",p)
			Y.Part0 = User.Character:FindFirstChild(u.Name)
			Y.Part1 = u.Middle
			Y.C0 = CFrame.new(0, 0, 0)
			p.CanCollide = false
			p.Anchored = false
		end
	end
end

EX:

MorphUser(Player,“TFO”,“Heroes”,“Phasma”,“Morph”)

From looking at that nothing screams memory leak. If there is a problem with the morphing it may be to do with calling the function repeatedly, could you show us where the MorphUser(Player,“TFO”,“Heroes”,“Phasma”,“Morph”) is called?

How it is called is very ugly… So be aware!

Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character)
	visible = false
	pack = true
	invis = false
	Character.Humanoid.WalkSpeed = 11
	wait(2)
	for _,v in pairs(Character:GetChildren()) do
		if v:IsA('BasePart') then
			v.Material = Enum.Material.Fabric
		end
	end
	Body(1,1,1,Character)
	--TFO--
	pauld = false
	if Player:IsInGroup(2847797) then
		for _,v in pairs(Character:GetChildren()) do
			if v:IsA('BasePart') and v.Name ~= 'Head' then
				v.Transparency = 1
		end
		--SNOKE--
		if Player.UserId == 361092508 then
			Body(1,1.5,1,Character)
			--Character.Humanoid.HeadScale.Value = 10
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
			MorphUser(Player,"TFO","Heroes","Snoke","Morph")
		--KYLO--
		elseif Player.UserId == 108287933 then
			MorphUser(Player,"TFO","Heroes","Kylo","Morph")
			UIgiver(Player,"Kylo")
			Character.Head.Transparency = 1
			Character.Head.face.Texture = "rbxassetid://497311576"
		--HUX---
		elseif Player.UserId == 44952876 then
			Body(1,1,0.85,Character)
			MorphUser(Player,"TFO","Heroes","Hux","Morph")
			MorphUser(Player,"Addons","Addons","Coat","Coat")
			UIgiver(Player,"Officer")
		--ENGINEER--
		elseif Player:GetRankInGroup(2847797) == 14  then
			Body(1,1,0.85,Character)
			MorphUser(Player,"TFO","TFO","Admiral","Morph")
			MorphUser(Player,"Addons","Addons","Coat","Coat")
			UIgiver(Player,"Officer")
		--PHASMA--
		elseif Player.UserId == 46061086 then
			MorphUser(Player,"TFO","Heroes","Phasma","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		--STONE--
		elseif Player.userId == 0 then
			MorphUser(Player,"TFO","Heroes","Stone","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		--KOR--
		elseif Player.UserId == 48174348 then
			MorphUser(Player,"TFO","Heroes","Monk","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		elseif Player.UserId == 262450654 then
			MorphUser(Player,"TFO","Heroes","Armory","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		elseif Player.UserId == 423159794 then
			MorphUser(Player,"TFO","Heroes","Sniper","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		elseif Player.UserId == 40828571 then
			MorphUser(Player,"TFO","Heroes","Rogue","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		elseif Player.UserId == 103098076 or Player.UserId == 554887434 then
			MorphUser(Player,"TFO","Heroes","Knight","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		--CARDINAL--
		elseif Player.UserId == 88284270 then
			MorphUser(Player,"TFO","Heroes","Cardinal","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		--FOSB DIRECTOR--
		elseif Player.UserId == 169093723 then
			Body(1,1,0.85,Character)
			MorphUser(Player,"TFO","Heroes","Director","Morph")
			MorphUser(Player,"Addons","Addons","Coat","Coat")
			UIgiver(Player,"Officer")
		--TFO DIVISIONS--
		elseif Player:IsInGroup(3538427) then
			pauld = true
			MorphUser(Player,"TFO","Division","Executioner","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		elseif Player:IsInGroup(4021367) then
			pauld = false
			if Player:GetRankInGroup(4021367) >= 5 then
				MorphUser(Player,"TFO","Division","SF","Morph")
				Character.Head.Transparency = 1
				Character.Head.face.Transparency = 1
			elseif Player:GetRankInGroup(4021367) >= 4 then
				MorphUser(Player,"TFO","Division","TR","Morph")
				Character.Head.Transparency = 1
				Character.Head.face.Transparency = 1
			else
				MorphUser(Player,"TFO","Division","SF","Morph")
				Character.Head.Transparency = 1
				Character.Head.face.Transparency = 1
			end
		elseif Player:IsInGroup(3516424) then
			pauld = false
			MorphUser(Player,"TFO","Division","Pilot","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
			if Player:GetRankInGroup(3516424) >= 175 then
				MorphUser(Player,"Addons","Colours","P3","Add")
			elseif Player:GetRankInGroup(3516424) >= 125 then
				MorphUser(Player,"Addons","Colours","P2","Add")
			else
				MorphUser(Player,"Addons","Colours","P1","Add")
			end
		elseif Player:IsInGroup(3319117) then
			pauld = false
			if Player:GetRankInGroup(3319117) >= 252 then
				MorphUser(Player,"TFO","Division","Legatus","Morph")
				Character.Head.Transparency = 1
				Character.Head.face.Transparency = 1
			elseif Player:GetRankInGroup(3319117) >= 254 then
				MorphUser(Player,"TFO","Division","Centurion","Morph")
				Character.Head.Transparency = 1
				Character.Head.face.Transparency = 1
			else
				MorphUser(Player,"TFO","Division","PG","Morph")
				Character.Head.Transparency = 1
				Character.Head.face.Transparency = 1
			end
		elseif Player:IsInGroup(3014038) then
			pauld = true
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
			MorphUser(Player,"TFO","TFO","Storm","Morph")
			MorphUser(Player,"Addons","Addons","Heavy","Add")
		elseif Player:IsInGroup(3011525) then
			pauld = true
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
			MorphUser(Player,"TFO","Division","Flame","Morph")
		elseif Player:IsInGroup(3014109) then
			pauld = true
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
			MorphUser(Player,"TFO","TFO","Storm","Morph")
		--TFO OFFICERS--
		elseif Player:GetRankInGroup(2847797) >= 7 then
			Body(1,1,0.85,Character)
			pauld = false
			MorphUser(Player,"Addons","Addons","Coat","Coat")
			UIgiver(Player,"Officer")
			if Player:IsInGroup(3010217) then
				MorphUser(Player,"TFO","Division","FOSB","Morph")
				MorphUser(Player,"Addons","Addons","Overalls","Add")
			elseif Player:GetRankInGroup(2847797) >= 13 then
				MorphUser(Player,"TFO","TFO","Colonel","Morph")
			elseif Player:GetRankInGroup(2847797) >= 12 then
				MorphUser(Player,"TFO","TFO","Major","Morph")
			elseif Player:GetRankInGroup(2847797) >= 11 then
				MorphUser(Player,"TFO","TFO","Captain","Morph")
			elseif Player:GetRankInGroup(2847797) >= 10 then
				MorphUser(Player,"TFO","TFO","Lieutenant","Morph")
			elseif Player:GetRankInGroup(2847797) >= 8 then
				MorphUser(Player,"TFO","TFO","FirstSarge","Morph")
			elseif Player:GetRankInGroup(2847797) >= 7 then
				MorphUser(Player,"TFO","TFO","MasterSarge","Morph")
			end
		--TFO TROOPER--
		elseif Player:IsInGroup(2847797) then
			pauld = true
			MorphUser(Player,"TFO","TFO","Storm","Morph")
			Character.Head.Transparency = 1
			Character.Head.face.Transparency = 1
		end
		--TFO PAULDRONS--
		if pauld == true then
			if Player:GetRankInGroup(2847797) >= 6 then
				MorphUser(Player,"Addons","Addons","Pauldron4","Pauld")
			elseif Player:GetRankInGroup(2847797) >= 5 then
				MorphUser(Player,"Addons","Addons","Pauldron3","Pauld")
			elseif Player:GetRankInGroup(2847797) >= 4 then
				MorphUser(Player,"Addons","Addons","Pauldron2","Pauld")
			elseif Player:GetRankInGroup(2847797) >= 3 then
				MorphUser(Player,"Addons","Addons","Pauldron1","Pauld")
			end
		end
		if visible == false and Character:FindFirstChild('Morph') ~= nil then
			Finale(Character)
		end
	end
	end
end)

end)

Although very displeasing to the eye, that code also doesn’t seem to be causing your leak, try disabling individual scripts and checking if there is a major change.

Whenever a user resets or the morph loads in it lags the server. Thats the main problem

I’ve been having this issue in my game for the past couple weeks.

The server’s ping would skyrocket, and it never ever did that before. I reverted the game 1 month prior to the first occurrence of this bug and my game still has the issue.

Yes. The game didn’t lag badly before- now it seems awful.

By the way you should replace the ‘:remove()’ function calls in your scripts as this method is deprecated. This could be a small contributor to your issue as the remove function doesn’t properly remove instances like ‘Destroy()’ does.

Also, looking at the characters after morphing, what is the distribution and amount of welds in the morph?

That shouldnt cause actual lag (such as animations not running & chat being delayed) It should only cause FPS lag I though?

I will update the remove function.