Hello, I have a gui that moves by WASD
My problem is that if you hold W and S at the same time, cancelling eachother, then it won’t register holding A or D
If you do opposite and hold A and D then press W or S it will work
The code:
local function IsBeingPressed()
local MovingUp = false
local MovingDown = false
local MovingLeft = false
local MovingRight = false
if Setting == "Arrows" then
if UIS:IsKeyDown(Enum.KeyCode.Up) then MovingUp = true end
if UIS:IsKeyDown(Enum.KeyCode.Down) then MovingDown = true end
if UIS:IsKeyDown(Enum.KeyCode.Left) then MovingLeft = true end
if UIS:IsKeyDown(Enum.KeyCode.Right) then MovingRight = true end
elseif Setting == "WASD" then
if UIS:IsKeyDown(Enum.KeyCode.W) then MovingUp = true end
if UIS:IsKeyDown(Enum.KeyCode.S) then MovingDown = true end
if UIS:IsKeyDown(Enum.KeyCode.A) then MovingLeft = true end
if UIS:IsKeyDown(Enum.KeyCode.D) then MovingRight = true end
end
return MovingUp, MovingDown, MovingLeft, MovingRight
end
local MoveSpeed = 10
RS.RenderStepped:Connect(function()
local MovingUp, MovingDown, MovingLeft, MovingRight = IsBeingPressed()
local FuturePos = Plr.Position
FuturePos = Vector2.new(FuturePos.X.Offset, FuturePos.Y.Offset)
if MovingUp then FuturePos = Vector2.new(FuturePos.X, FuturePos.Y - MoveSpeed) end
if MovingDown then FuturePos = Vector2.new(FuturePos.X, FuturePos.Y + MoveSpeed) end
if MovingRight then FuturePos = Vector2.new(FuturePos.X + MoveSpeed, FuturePos.Y) end
if MovingLeft then FuturePos = Vector2.new(FuturePos.X - MoveSpeed, FuturePos.Y) end
if IsInBounds(FuturePos) then Plr.Position = UDim2.new(0, FuturePos.X, 0, FuturePos.Y) end
end)