Making a held input into a server script

alr so im trying to use a remote event in a local script to be able to have a input that is held go into a sever script (im trying to do hold F to block)

i dont know how remote event works but some of u guys are to bigbrain for this

right now all i have is


image

but this only works for button tap fuctions
im wondering if anybody can add onto this or have a diffrent section onto the script to make it be able to run held buttons instead of pressing a button and having the key = to that button till another button is pressed
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

any help will be appreciated as always

Use .InputEnded in order to stop blocking

local userInput = game:GetService("UserInputService")
local replicated = game:GetService("ReplicatedStorage")
local blockRemote = replicated:WaitForChild("BlockRemote") --Example remote event.

local connection

userInput.InputBegan:Connect(function(keyStart, processed)
	if processed then return end

	if keyStart.KeyCode == Enum.KeyCode.F then
		local startTime = tick()
		connection = userInput.InputEnded:Connect(function(keyEnd, processed)
			if processed then return end

			if keyEnd.KeyCode == Enum.KeyCode.F then
				local endTime = tick()
				local heldTime = endTime - startTime
				print("'F' key held for "..heldTime.." seconds.")
				if heldTime > 1 then
					blockRemote:FireServer()
				end
				connection:Disconnect()
			end
		end)
	end
end)

Here’s a script which will fire a RemoteEvent instance when the “F” key is held for a duration of 1 or more seconds.