UserInputService registering two times

Hello,
I am trying to make it so that the player presses ‘T’ or ‘ButtonL2’ to get the function running but it registers the user input 2 times and I don’t know whats causing the issue. It should only be registering the input once like normal.

UIS.InputBegan:Connect(function(input,gp)
	if gp == false then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.T and d == 0 then
				warn(input.KeyCode) -- prints the output below
				d = 1
				updateOrChange("change")
				wait()
				d = 0
			end
		elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
			if input.KeyCode == Enum.KeyCode.ButtonL2 then
				updateOrChange("change")
				d = 1
				wait()
				d = 0
			end
		end
	end
end)

Here is the output (notice the highlighted times, meaning it registered 2 times which only should be registered once):

Anyway, how do I fix the issue

It is probably showing the InputBegan and InputEnded events. Try just using one of those events or putting a debounce on it.

2 Likes

Try checking if Input.UserInputState == Enum.UserInputState.End. This will ensure the input has ended, rather than processing initial key presses or gradual interaction.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.