InputEnded Detector may Be Faulty

I want to detect when a player’s input has ended

image
image

It doesn’t detect when the input has ended
I tried adding 2 different debounce for each situation

--# Variables
local UIS = game:GetService("UserInputService")
local RPS = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")

local Player = game:GetService("Players").LocalPlayer
local BarrierCrash = RPS:WaitForChild("BarrierCrash")
local Key = script:WaitForChild("Key").Value

local HoldDebounce = true
local ReleaseDebounce = true
local cooldown = 2


Player.CharacterAdded:Connect(function(Character)
	local Humanoid = Character:WaitForChild("Humanoid")
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	
	UIS.InputBegan:Connect(function(input,chat)
		
		if chat then return 	
		elseif input.KeyCode == Enum.KeyCode[Key] and Character and HoldDebounce == true then
			HoldDebounce = false
			ReleaseDebounce = true
			BarrierCrash:FireServer("Hold")
			print("Started".." R ".. tostring(ReleaseDebounce), " H ".. tostring(HoldDebounce))
		end
	end)
	
	UIS.InputEnded:Connect(function(input,chat)
		if input.KeyCode == Enum.KeyCode[Key]  and Character and ReleaseDebounce == true and HoldDebounce == false then
			ReleaseDebounce = false
			BarrierCrash:FireServer("Release")
			print("Ended")
		end
	end)
	
end)


BarrierCrash.OnClientEvent:Connect(function()	
	task.wait(cooldown)
	HoldDebounce = true
end)
1 Like

On input ended change HoldDebounce to true.

It doesn’t make a difference it still happens
if I hold a key down for a couple seconds it sometimes doesn’t fire

If you leave absolutely all controls of your device, including mouse movement and touch, only then the InputEnded event fires. You should add an InputChanged event where you detect if the certain key is held down.

--# Variables
local UIS = game:GetService("UserInputService")
local RPS = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")

local Player = game:GetService("Players").LocalPlayer
local BarrierCrash = RPS:WaitForChild("BarrierCrash")
local Key = script:WaitForChild("Key").Value

local HoldDebounce = true
local ReleaseDebounce = true
local cooldown = 2


Player.CharacterAdded:Connect(function(Character)
	local Humanoid = Character:WaitForChild("Humanoid")
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	
	UIS.InputBegan:Connect(function(input,chat)
		
		if chat then return 	
		elseif input.KeyCode == Enum.KeyCode[Key] and Character and HoldDebounce then
			HoldDebounce = false
			ReleaseDebounce = true
			BarrierCrash:FireServer("Hold")
			print("Started".." R ".. tostring(ReleaseDebounce), " H ".. tostring(HoldDebounce))
		end
	end)
	
UIS.InputChanged:Connect(function(input,chat)
		if not UIS:IsKeyDown(Enum.KeyCode[Key])  and Character and ReleaseDebounce and not HoldDebounce and not chat then
			ReleaseDebounce = false
			BarrierCrash:FireServer("Release")
			print("Ended")
		end
	end)


	UIS.InputEnded:Connect(function(input,chat)
		if input.KeyCode == Enum.KeyCode[Key]  and Character and ReleaseDebounce and not HoldDebounce and not chat then
			ReleaseDebounce = false
			BarrierCrash:FireServer("Release")
			print("Ended")
		end
	end)
	
end)


BarrierCrash.OnClientEvent:Connect(function()	
	task.wait(cooldown)
	HoldDebounce = true
end)

Hope this helps! :smile:

1 Like

image
I still run into the same problem
The moment I held it down for longer and released none of them detected
It was supposed to print Ended :neutral_face:

1 Like