Is there a way to simulate a button press without pressing the button?

Trying to have a crouching system where some areas you cannot stop crouching, this way i thought what if there is a part where whenever you touch it the game thinks you are holding down c, the crouching bind, and you wouldnt be able to stop? the script below doesnt work

local part = script.Parent


local function HoldC()
	local input = game:GetService("UserInputService")
	input.KeyEvent:Fire({ KeyCode = Enum.KeyCode.C, UserInputType = Enum.UserInputType.Keyboard }, true)
end


local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
	if humanoid then
		HoldC()
	end
end

part.Touched:Connect(onTouch)

That’s a good question and that’s what I’m searching for the moment

Can’t you just do what the button would do when they touch the part

2 Likes