How to detect Input changes within an InputBegan function

I’d like to see changes within a function that’s running, which is started by the UserInputService InputBegan event. I have my code below:

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
			repeat
				print(input.Position) -- Desired changing position
			until input.UserInputState == Enum.UserInputState.End or input.UserInputState == Enum.UserInputState.Cancel
		end
	end
end)

The Desired changing position, shown by print(input.Position) does not change whilst the input does - the input being MOVING the mouse whilst HOLDING down the LEFT BUTTON. It does update however upon the input ENDING (no longer clicking the mouse button).

Why isn’t it possible to retrieve the mouse position mid-input (i.e., after starting input but before ending it), or, how would it be possible?

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
			print("Mouse Clicked")
		end
	end
end)
UserInputService.InputChanged:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		if input.UserInputType == Enum.UserInputType.MouseMovement then
			print("Mouse Moved")
		end
	end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
			print("Mouse Released")
		end
	end
end)

You can use a variable to keep track of what state of input the player is currently in.

Thank you - this is the solution I utilised a bit after posting, however I hadn’t written up a follow up yet. I use a variable that gets changed by UserInputService.InputChanged event, which basically updates the current input (so tap, click etc.). The repeat until in the InputBegan event function uses the variable, works perfectly.

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