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

Can anyone figure out how to add Debounce to uis.inputended?

****MY big ugly code dont hate ;(

local req = 0
local LCV  --Lets make this nill
local deb = false 

uis.InputBegan:connect(function(input, GPE)
	if GPE then return end
	if input.KeyCode == Enum.KeyCode.E then
		if not deb then
		deb = true
		req = 0
        LCV = true
		
		local human = char.Humanoid
		ani.AnimationId = "http://www.roblox.com/asset?id=387149840"
			if human then
				local load = human:LoadAnimation(ani)
				if load then
				load:Play()
			end
		end	
	
	
		while LCV do
		wait(1)
		req = req + 1
		print 'added 1'
		end
		
	
		end
		
	wait(2)
	deb = false
	print 'cooled'
		end
end)



uis.InputEnded:connect(function(input)--Aftet button was released
	if input.KeyCode == Enum.KeyCode.E then
        LCV = false
		print(req)
		ani.AnimationId = "http://www.roblox.com/asset?id=387152305"

		local hu = char.Humanoid
		if hu then
			local load = hu:LoadAnimation(ani)
			if load then
			load:Play()
			
			wait(2)
			load:Stop()
			end
		end	
	end
end)

1 answer

Declare the debounce variable outside the function and change it within the function. That way, the variable isn't overridden every time you run the function.

local debounce = false --look at me! I'm outside the function!

function doStuff()
	if debounce then --return nothing and exit the function if debounce is true
		return
	else
		debounce = true
		--do stuff!
		debounce = false
	end
end

2 comments

0

isnt very helpful i already know how this works....

0

So then use the same principle for InputEnded.

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