How to tell when player is holding thumbstick in certain direction

I want to know if a player is holding their thumbstick left or right, without using player movement as a basis (character doesn’t exist in use case)

The delta will eventually return to 0, even though my thumbstick is to the right or left still, so I need to know when they currently have it left or right

game:GetService("UserInputService").InputChanged:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Thumbstick1 then
		print(input.Delta.X)
	end
end)

Replace input.Delta with input.Position. Delta is just the difference from the current frame and the last frame.

2 Likes

Just like @bluebxrrybot said, you have to use InputObject.Position. The problem was that you were using InputObject.Delta, which basically tracks the changes in position between the previous frame and the current one. This is useful sometimes, but probably not in your case.

Here is some demo code that you can use as a reference for what you want to do:

-- Services --

local UserInputService = game:GetService("UserInputService")

-- Scripting --

UserInputService.InputChanged:Connect(function(Input, GameProcessed) 	-- Thumbstick positions can only be retrieved by the "InputChanged" function, "InputBegan" does not work
	if Input.UserInputType == Enum.UserInputType.Gamepad1 then			-- Make sure that it is a controller (in this case, the first one connected)
		if Input.KeyCode == Enum.KeyCode.Thumbstick1 then				-- Currently checking only the right thumbstick
			local PositionX = Input.Position.X							-- Retrieve X-Axis position (-1 is far left and 1 is far right)
			local PositionY = Input.Position.Y							-- Retrieve Y-Axis position (-1 is far down and 1 is far up)
			
			print("X: "..PositionX)
			print("Y: "..PositionY)
			
			print("\n")
		end
	end
end)

Hopefully this helped.