How to make a player crouch?(In code)

You know, I want to use it so it works like this:

tracedata.start = pl:EyePos() + (pl:GetUp() * 38) + (pl:GetForward() * 1)
		tracedata.endpos = pl:EyePos()+ (pl:GetUp() * 50) + (pl:GetForward() * 64)
		tracedata.filter = pl
		if trace.Hit then
crouch -- but not toggle(use RunConsoleCommand), because, I want it so when the trace doesnt hit you can crouch and stand.

Thanks and sorry for my bad english

I don’t know of a way to force them crouch other than the console commands. I would approach it like this:

–Determine if they are already crouching, and if it’s because we forced them to
local IsCrouching = ply:Crouching()
local WasForced = ply.ForcedCrouching or false

if not IsCrouching then
–We aren’t crouching yet, so do the trace and see if we need to crouch
– todo: trace goes here
if trace.Hit then
–Force them to crouch
ply.ForcedCrouching = true
–We are already crouching, check if it was forced?
if WasForced then
–Check if we can stand up yet
–todo: trace goes here
if not trace.Hit then
–Force them to stand up, and reset our ‘forced status’
ply.ForcedCrouching = false

Well I tried to do something like that.
It works wierdly. You see, I used “RunConsoleCommand(”+duck") and it worked fine when it forces the player to crouch, but, when you try to make the player stand up, it just doesnt work. The command doesnt wants to work. (I’m talking about RunConsoleCommand("-duck"))

Force it in CreateMove

[lua]function GM:CreateMove(cmd)
if, IN_DUCK) == 0 then
cmd:SetButtons(cmd:GetButtons() + IN_DUCK)

why do people use when you can easily check it by doing cmd:KeyDown

also you should use with cmd:SetButtons because that’s the proper way

Might as well do this if you really want to nitpick.

[lua]function GM:CreateMove(cmd)
cmd:SetButtons(bit.bor(cmd:GetButtons(), IN_DUCK))

How can I use this with the trace that I wrote down?