Touched Event Firing MANY Times

So I was making a game where you can collect gem like things and it would add size to your character but for some reason it fires a bunch of times. I’ve tried many solutions and I can’t figure out how to get it to fix.
Here’s my code:

local tings = {}

while wait() do
	for i,part in pairs(workspace.Gems:GetChildren()) do
		if part.Name:find("GemThingy") and not table.find(tings, part.Name) then
			print("New part added")
			table.insert(tings, part.Name)
			part.Touched:Connect(function(part2)
				if part2.Parent:FindFirstChild("Humanoid") and part.Name == "Head" then
					part2.Parent.Head.Size += part.Size * Vector3.new(0.5, 0.5, 0.5)
					part2.Parent.HumanoidRootPart.Size += part.Size * Vector3.new(0.5, 0.5, 0.5)
					part:Destroy()
				end
			end)
		end
	end
end
local tings = {}
local debounce = false
while wait() do
	for i,part in pairs(workspace.Gems:GetChildren()) do
		if part.Name:find("GemThingy") and not table.find(tings, part.Name) and debounce == false then
			debounce = true
            print("New part added")
			table.insert(tings, part.Name)
			part.Touched:Connect(function(part2)
				if part2.Parent:FindFirstChild("Humanoid") and part.Name == "Head" then
					part2.Parent.Head.Size += part.Size * Vector3.new(0.5, 0.5, 0.5)
					part2.Parent.HumanoidRootPart.Size += part.Size * Vector3.new(0.5, 0.5, 0.5)
					part:Destroy()
                   debounce = true
				end
			end)
		end
	end
end

I think this should work?

1 Like

It’s a lot better but it still fires twice when touched.

Nevermind, I found my own fix, sorry.

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