How to create debounce on individual parts?

I’m trying to create a tornado that uses body velocity to fling parts. I’ve tried adding a debounce so that when the tornado collides with a part, it doesn’t clone the velocity into said part a million times, however I haven’t been succesful and havent found anything online that was helpful. What can I do to solve my problem? (The block of code beneath is just a sample of the full script since most of the code presented basically repeats itself via elseif but with slight changes to some values).

local funnel = script.Parent
local destroy_weaker_parts = false 

local overlapparams = OverlapParams.new()

local funnelsize = funnel.Size


	while true do
		wait()
	local hitcontent = workspace:GetPartBoundsInBox(funnel.CFrame,Vector3.new(funnel.Size.X, funnelsize.Y, funnel.Size.Z), overlapparams)
	for i, v in pairs(hitcontent) do
	R1 = math.random(1,150)
	R2 = math.random(1,150)
		if funnel.Windspeed.Value >= 65  and funnel.Windspeed.Value < 86 then
			if v.Name == "F0" then
			v.Anchored = false
			 funnel.Damage.fling:Clone().Parent = v
				funnel.Damage.fling2:Clone().Parent = v
				if v:FindFirstChild("fling") then
					v.fling.Velocity = Vector3.new(R1, 100, R2)
				end
			
				print("F0 Damage")
			end
			if v.Name == "Glass" then
			funnel.glassbreak:Clone().Parent = v
				v.glassbreak:Play()
				v:Destroy()
			end
4 Likes

You could simply implement a BoolValue into each part, and use that as your debounce.

You can use Attributes as a Value and make it true if your Function did fired so it dont fire another Time.

2 Likes

Use tables

local debounce = {} 
---do the hit detection or stuff here, *part* is the part detected
if not debounce[part] then
debounce[part] = true
end
1 Like

To finish off listing all types of value holding methods, you can use module scripts. It’s basically like using tables but other scripts will be able to access it. If other scripts don’t need to access it though, it’s unnecessary. But to do this, you basically do @CKY_DRAGON’s method, but you use the debounce table as a required module script instead.

Why create objects and take up memory when you can use tables instead

You could check if there is a body velocity already in there before cloning it and putting it in.