Why do the other functions not work?

local TARGET_SPEED = 10
local w = false
local a = false
local s = false
function stopmove(input)
if input.KeyCode == Enum.KeyCode.W then
w = false
end
if input.KeyCode == Enum.KeyCode.A then
a = false
end
if input.KeyCode == Enum.KeyCode.S then
s = false
end
end
function forward(input)
if input.KeyCode == Enum.KeyCode.W then
w = true
repeat wait()
px,py,pz,xx,yx,zx,xy,yy,zy,xz,yz,zz = cam.CoordinateFrame:components()
char.player.forward.AngularVelocity = Vector3.new(-xx * TARGET_SPEED,0,zx * TARGET_SPEED)
print(input.KeyCode)
until w == false
char.player.forward.AngularVelocity = Vector3.new(0,0,0)
end
end
function back(input)
if input.KeyCode == Enum.KeyCode.S then
s = true
repeat wait()
px,py,pz,xx,yx,zx,xy,yy,zy,xz,yz,zz = cam.CoordinateFrame:components()
char.player.back.AngularVelocity = Vector3.new(xx * TARGET_SPEED,0,-zx * TARGET_SPEED)
print(input.KeyCode)
until s == false
char.player.back.AngularVelocity = Vector3.new(0,0,0)
end
end
function left(input)
if input.KeyCode == Enum.KeyCode.A then
a = true
repeat wait()
px,py,pz,xx,yx,zx,xy,yy,zy,xz,yz,zz = cam.CoordinateFrame:components()
char.player.left.AngularVelocity = Vector3.new(-xz * TARGET_SPEED,0,xx * TARGET_SPEED)
print(input.KeyCode)
until a == false
char.player.left.AngularVelocity = Vector3.new(0,0,0)
end
end
userinput.InputBegan:Connect(left)
userinput.InputEnded:Connect(stopmove)
userinput.InputBegan:Connect(forward)
userinput.InputBegan:Connect(back)

when I play test this it registers the input, but only when I press w.
I have already tried combining the functions into one but no luck.
I’m really unsure what to do here

Indent your code please, no one will bother reading it if you don’t.

why not just have left, forward, and back as one function you connect to InputBegan once.

function began(input)
  if input.KeyCode == Enum.KeyCode.W then
    --forward() code
  elseif input.KeyCode == Enum.KeyCode.A then
    --left() code
  elseif input.KeyCode == Enum.KeyCode.S then
    --back() code
  end
end

userinput.InputBegan:Connect(begin)

(Not sure if this will fix it, but it might.)

sorry about that

local TARGET_SPEED = 10
local w = false
local a = false
local s = false

function stopmove(input)
if input.KeyCode == Enum.KeyCode.W then
w = false
end
if input.KeyCode == Enum.KeyCode.A then
a = false
end
if input.KeyCode == Enum.KeyCode.S then
s = false
end
end

function forward(input)
if input.KeyCode == Enum.KeyCode.W then
w = true
repeat wait()
px,py,pz,xx,yx,zx,xy,yy,zy,xz,yz,zz = cam.CoordinateFrame:components()
char.player.forward.AngularVelocity = Vector3.new(-xx * TARGET_SPEED,0,zx * TARGET_SPEED)
print(input.KeyCode)
until w == false
char.player.forward.AngularVelocity = Vector3.new(0,0,0)
end
end

function back(input)
if input.KeyCode == Enum.KeyCode.S then
s = true
repeat wait()
px,py,pz,xx,yx,zx,xy,yy,zy,xz,yz,zz = cam.CoordinateFrame:components()
char.player.back.AngularVelocity = Vector3.new(xx * TARGET_SPEED,0,-zx * TARGET_SPEED)
print(input.KeyCode)
until s == false
char.player.back.AngularVelocity = Vector3.new(0,0,0)
end
end

function left(input)
if input.KeyCode == Enum.KeyCode.A then
a = true
repeat wait()
px,py,pz,xx,yx,zx,xy,yy,zy,xz,yz,zz = cam.CoordinateFrame:components()
char.player.left.AngularVelocity = Vector3.new(-xz * TARGET_SPEED,0,xx * TARGET_SPEED)
print(input.KeyCode)
until a == false
char.player.left.AngularVelocity = Vector3.new(0,0,0)
end
end

userinput.InputBegan:Connect(left)
userinput.InputEnded:Connect(stopmove)
userinput.InputBegan:Connect(forward)
userinput.InputBegan:Connect(back)`


I tried doing that, and it worked.
But I cannot combine movements