I have been creating a camera part that has a body velocity inside of it so when the player holds in w, a, s or d it will move in the respective direction. The script is a local script inside of playergui so the part will only move on client which I want. However when I test it, it does not work. The part is not anchored and I am not sure why it isn't moving
Local script inside of StarterGui:
wHeld = false
aHeld = false
sHeld = false
dHeld = false
qHeld = false
eHeld = false
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
wHeld=true
end
end)
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.A then
aHeld=true
end
end)
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.S then
sHeld=true
end
end)
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.D then
dHeld=true
end
end)
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
qHeld=true
end
end)
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
eHeld=true
end
end)
game:GetService("UserInputService").InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
wHeld=false
end
if input.KeyCode == Enum.KeyCode.A then
aHeld=false
end
if input.KeyCode == Enum.KeyCode.S then
sHeld=false
end
if input.KeyCode == Enum.KeyCode.D then
dHeld=false
end
if input.KeyCode == Enum.KeyCode.Q then
qHeld=false
end
if input.KeyCode == Enum.KeyCode.E then
eHeld=false
end
end)
while wait() do
if wHeld==true then
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 0, 5)
else
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
end
if aHeld==true then
workspace.campart.BodyVelocity.Velocity = Vector3.new(5, 0, 0)
else
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
end
if sHeld==true then
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 0, -5)
else
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
end
if dHeld==true then
workspace.campart.BodyVelocity.Velocity = Vector3.new(-5, 0, 0)
else
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
end
if qHeld==true then
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, -5, 0)
else
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
end
if eHeld==true then
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 5, 0)
else
workspace.campart.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
end
end
