Part cloning a part WAYY too many times

I’m trying to create reflections but I’ve encountered a problem. When I put the character in-front of it to test, it clones the character WAYY to many times and almost crashes my ROBLOX studio. And no, this is 100% not because of a virus. Here’s what I’ve tried:
NOT THE FULL CODE

function lighting.reflect(partthatreflects, partthatemmits, parttoreflectonto)
	local hasbeenhit = false
	local ray = script.Ray:Clone()
	local tweenservice = game:GetService("TweenService")
	local info = TweenInfo.new(3, Enum.EasingStyle.Linear,Enum.EasingDirection.Out, 100000000000, true, 0)
	local goal = {
		Size = Vector3.new(partthatreflects.Size.X, partthatreflects.Size.Y, 2048)
	}	
	ray.Position = partthatemmits.Position
	ray.Parent = workspace
	local created = tweenservice:Create(ray, info, goal)
	created:Play()
	ray.Touched:Connect(function(hit)
		local debounce = false
		hasbeenhit = true
		local clone = hit:Clone()
		debounce = true
		wait(10)
		debounce = false
		if hasbeenhit == true  then
			local debounce = false
			clone.Position = parttoreflectonto.Position
			clone.Parent = workspace
			debounce = true
			wait(1)
			debounce = false
		end
		
	end)
end

What it does:

https://gyazo.com/e211189cceec3392905af4fa9df6b714

Yes, I know the part’s can collide is true.

You’re not checking the state of the debounce–and you should define the debounce outside of the scope of the function.

local debouce = false

ray.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        hasbeenhit = true

        local clone = hit:Clone()

        wait(10)
        debounce = false
    end
end)

Actually your understanding of a debounce seems to be wrong. The point of a debounce is to be a variable that is considered each function call to state whether the function should continue.

1 Like

Now it has stopped cloning my character unfortunately.