Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i limit the number of touche events playing?

script.Parent.Blade.Touched:connect(function(hit)
	if equipped and humanoid  and humanoid.Health >=0 then
	print(hit.Parent.Name)
	target = hit.Parent:FindFirstChild'Humanoid'
		if target and target.Health >= 0 then
			print(hit.Parent.Name)
			target:TakeDamage(damage.Value)
			end
	end
end)

the code fires like 5 touched events when ever it hits something with a humanoid

1 comment

0

how do i limit the number of touched events firing?

1 answer

✓ Accepted answer
local deb = true

script.Parent.Blade.Touched:connect(function(hit)
    if equipped and humanoid  and humanoid.Health >=0 and deb == true then
	deb = false
    print(hit.Parent.Name)
    target = hit.Parent:FindFirstChild'Humanoid'
        if target and target.Health >= 0 then
            print(hit.Parent.Name)
            target:TakeDamage(damage.Value)
            end
wait()
	deb = true
    end
end)

Creating a debounce makes it so that the item can't be touched again for a certain amount of time.

This discussion is preserved as it was. New answers, comments, and votes are closed.