TouchReplication huge server memory usage

Hi, I’m not sure if I can get an answer to my question here, but I wanted to try anyway.
In my game, I have recently seen huge usage of TouchReplication in the servermemory.
I have also noticed some lag in my game, especially with gun firing (server events), and these problems may be related.
I am firstly wondering what can cause these problems.
I also have some examples of what could cause these problems.

Here’s the dev console with the graph. It does empty over time (into untracked memory), but it often increases quicker than it empties.

It’s a Tycoon, so I firstly have a lot of buttons that you can touch and buy. I don’t think that’s the problem, since the problem didn’t arise until some time ago, while the Tycoon always has had those. Same goes for the drops that touch the upgrader and the collector. I think that’s all fairly standard, and shouldn’t cause any problems.

I don’t think it’s a problem with the weapon giver script, but I’ll list it here anyway.

Weapon Giver Script
local Weaponname = script.Parent.Weapon.Value
local dummy = true

local function Touched(part)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local player = game.Players:FindFirstChild(part.Parent.Name)
		if player.TeamColor == BrickColor.new(script.Parent.Parent.Parent.Parent.Name) or game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,1238574) then
			if dummy == true then
				dummy = false
				script.Parent.BrickColor = BrickColor.new("Really red")
				local duplicate1 = player.Backpack:FindFirstChild(Weaponname)
				if duplicate1 then
					duplicate1:Destroy()
				end
				local duplicate2 = player.Character:FindFirstChild(Weaponname)
				if duplicate2 then
					duplicate2:Destroy()
				end
				local weapon = game.ServerStorage:FindFirstChild(Weaponname)
				local w2 = weapon:Clone()
				w2.Parent = player.Backpack
				wait(5)
				script.Parent.BrickColor = BrickColor.new("Institutional white")
				dummy = true	
			end
		else
			game:GetService("MarketplaceService"):PromptGamePassPurchase(player,1238574)		
		end
	end
end

script.Parent.Touched:Connect(Touched)

I have also implemented the free Roblox soldier model recently, which may be the cause:

Is probably somewhat likely, but it has a few extensive scripts which I will not list here. If anyone had problems with the soldier model please let me know.

I’m honestly not sure, hopefully someone give examples of what can cause this large memory usage, and I can hopefully provide what it may be in my game. I hope you guys can work with this, sorry if you can’t.

It is a bit hard to pinpoint what the problem exactly is based on the information, BUT…

One common cause of overuse of TouchReplication I’ve seen in the past is deleting TouchInterests from tools. When they’re removed, the listeners for the TouchInterests don’t go away which causes lots of TouchReplication listeners at once.

If any of your code is removing TouchInterests from tool handles, you’ll want to rewrite them to not do so

1 Like

Thank you for your response and thinking with me! I’m pretty sure TouchInterests are not the problem, I can’t find anything in my scripts even referencing them.