How to make remote events run when a user is holding a button down

I want to make a system that when a user has a button pressed, a value is raised in the server (e.g. A car that when you are holding down W it speeds up). Can I achieve this without sending hundreds of remote events to the server every second while the user is holding down the button.

I don’t want something like this:

local uis = game:GetService("UserInputService")

while task.wait() do
	if uis:IsKeyDown(Enum.KeyCode.R) then
		-- Fires remote event 100 times every second
	end
end
1 Like

You can use user input event key down and key up to see when the key is pressed/released. This way you only need to fire the server twice, 1. when the key is initially pressed and held down, and 2. when the player releases the key