Extreme Lag Spike when proximity prompt is activated


In the video above, a proximity prompt is activated via an NPC, a particle effect plays, an animation plays, and then the NPC Disappears followed by another particle effect.

Both when the prompt is activated and when the NPC disappears there is a major lag spike

But here when I turn every single mesh transparency to 1, the lag is gone


The only thing I can think of is the accusive amount of mountain meshes, when I try to turn the render mode on performance, it says the mesh has too little tris. I can’t see a way to fix any of this.

Here is the script once the prompt is activated

if prompt.Name == "GiveJoke" and #jokes >= 1 and #jokes < player.HiddenStats.MaxJokes.Value + 1 then
		local npc = prompt.Parent.Parent
		local animation = npc.Animation
		local npcHumanoid = npc.Humanoid
		local stage = prompt.Parent.Parent.Parent
		local laughAnim = npcHumanoid:LoadAnimation(animation.Laugh)
		
		laughAnim.Priority = Enum.AnimationPriority.Action4
		
		if prompt.Parent.Parent.Parent.Configuration.StageName.Value == "Field" then
			quests.TellJokesAtFarm(game.ReplicatedStorage.Quest, player.Quests.TellJokesAtFarm)
		end
		
		laughAnim:Play()
		
		local chat = chats[math.random(1, #chats)]
		ChatService:Chat(npc.Head, chat, Enum.ChatColor.White)
		prompt.Enabled = false
		
		
		
		

		local coinNoises = npc.HumanoidRootPart.CoinSounds:GetChildren()
		local randomCoinNoise = coinNoises[math.random(1, #coinNoises)]
		randomCoinNoise:Play()

		for i, v in pairs(jokes) do
			
			spawn(function()
				jokeAbility[v.Name]()
				PlayParticalGroup(npc.HumanoidRootPart.LaughEffect, 3, npc.HumanoidRootPart.Position, ReplicatedStorage.Jokes[v.Name].Icon.Value)
			end)
			wait()
		end
		local popSound = game.StarterPlayer.Sounds.Pop
		wait(3.3)
		laughAnim:Stop()
		popSound:Play()
		spawn(function()
			DisappearEffect(npc.HumanoidRootPart, npc.HumanoidRootPart.Cloud)
		end)
		wait()
		npc:Destroy()
		wait(3)
		SpawnNpc(stage)

How often is this being run? Are you using a while loop or something else? I also recommend you use task.wait() and task.spawn() instead of wait() and spawn()

There are no loops, it is all connected to a function when the proximity prompt is fired, the function always lags no matter how often it is called, I will try to replace that wait and spawn with task.spawn & task.wait and see what happens

Edit: task.spawn and task.wait did not help what so ever

Found the issue, every time a particle effect played, it generated a new part.
Just made it so the particle plays from already existing parts.

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