Hold Key Bind for a player

I need a concept on how to make a hold key bind
i can do this (this is a localscript btw)

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function()
	
	print("pressed:)")
	
end)

uis.InputEnded:Connect(function()

	print("pressended")

end)

but if I did that it would only print once

you have to assign a key:

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(keycode)
	if keycode == Enum.KeyCode.E then
		print("pressed:)")
	end
end)

uis.InputEnded:Connect(function(keycode)
	if keycode == Enum.KeyCode.E then
		print("pressended")
	end
end)
1 Like

oh I forget to do that i was rushing a bit

I know it’s already been resolved but I’ll improve it.

local CAS = game:GetService("ContextActionService")

local UIS = game:GetService("UserInputService")

--[[

local function Dispositive()

return UIS.TouchEnabled and "Mobile" or UIS.GamepadEnabled and "XBOX" or "PC"

end

]] -- You don't need this, but work.

local function HoldKey(Name, State, Object)

if State == Enum.UserInputState.Begin then

print("Holding!")

elseif Enum.UserInputState.End then

print("Stopped Holding...")

end

end

CAS:BindAction("Hold",HoldKey,true,Enum.KeyCode.E, Enum.KeyCode.ButtonL1)
-- Name, function, buttonToMobile, Input1 or Input2
CAS:SetTitle("Hold", "HoldKey")
1 Like

I’m still learning more about scripting so my code may not be the best