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

Why is Ting/Debounce only working first time through script?

So this is a basic take damage script. Because of how often players can hit stuff, even 1 damage is op without a ting/debounce. Well so i put in one, and the results are funky.. I upped the ting time for testing reasons. I got hit once, waited 20 seconds, and then I was able to get hit as many times as i wanted, as if ting didn't exist anymore after the first touch.. I even printed ting and it always came back as 1..

Anyone know why?

local touch = script.Parent:FindFirstChild("Head")


local ting = 0 

function dmg(hit)
	if ting == 0 then
	ting = 1
	if hit.Parent ~= nil then
		local hum = hit.Parent:findFirstChild("Humanoid")
		if hum ~= nil then
			hum.Health = hum.Health - math.random(12,20)
		end
		end
	end
	wait(20) -- Here is my wait between activations
	ting = 0
end

touch.Touched:connect(dmg)

1 answer

Nevermind, I'm just tired I guess.

For anyone who wants a working damage script

local touch = script.Parent:FindFirstChild("Head")


local ting = 0 

function dmg(hit)
	if ting == 0 then
	 if hit.Parent ~= nil then
		local hum = hit.Parent:findFirstChild("Humanoid")
			if hum ~= nil then
			ting = 1
			hum.Health = hum.Health - math.random(12,20)
			wait(1)
			ting = 0
		    end
	 end
	end
end
touch.Touched:connect(dmg)

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