I made a dash system that allows the user to dash in a specified direction using Q and W, A, S, or D together. The system works alone, but when I start to press many keys it gets a little bit funky. If the user is walking forward with W and slightly to the left or right with A or D, and then decides to press Q to dash, I figured it would make sense for the system to sort of prioritize dashing to the left or right over dashing forward when the user is moving diagonally.
To achieve this, I put the elseifs with the left and right first so the script would prioritize those directions. With this, if I start running forward, I can still dash to the right. When I try going to the left, however, it doesn’t even render in UIS.InputBegan that I pressed a key in the first place.
I started experimenting with this, trying to find the issue. I put a print at the very top of UIS.InputBegan before any if statements or anything else. When I went to test it, with W and A already pressed down, it would not register that Q was being pressed. W, D, and Q seemed to work fine though, and they also activate the dash.
To experiment some more, I changed .InputBegan to .InputChanged: the same thing happened. I was starting to get tired of this weird bug so I put a while loop that prints all the keys I’m pressing, using UIS:GetKeysPressed(). Here’s a clip of what happened: link. The number it prints is the amount of keys being pressed, and all those other prints are other tests I did. The one that prints 5 booleans prints whether the Q, W, A, S, and D keys, respectively, are currently pressed, updated every time UIS.InputBegan runs.
The key count doesn’t go above 2 and it doesn’t dash in certain scenarios. Even when I press like 20 keys at the same time, the highest I’ve gotten it to acknowledge is up to 6 keys, but it usually only registers about 2 or 3.
So to my question. Does anyone know why the heck UIS doesn’t register certain combinations of keys? Is it something on my end? Here’s my dashing script, prints included, as a local script in StarterCharacterScripts:
-- Services
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local UIS = game:GetService("UserInputService")
-- Player Variables
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local root = char:WaitForChild("HumanoidRootPart")
-- Animations
local wDash = hum.Animator:LoadAnimation(script:WaitForChild("WDash"))
local aDash = hum.Animator:LoadAnimation(script:WaitForChild("ADash"))
local sDash = hum.Animator:LoadAnimation(script:WaitForChild("SDash"))
local dDash = hum.Animator:LoadAnimation(script:WaitForChild("DDash"))
-- Dash Variables
local dashDist = 25
local lastDash = 0
local dashCD = 2
-- Input Began
print('script running')
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
print('input')
print(gameProcessedEvent, os.clock() - lastDash < dashCD)
if gameProcessedEvent or os.clock() - lastDash < dashCD then return end
-- Input Variables
local q = UIS:IsKeyDown(Enum.KeyCode.Q)
local w = UIS:IsKeyDown(Enum.KeyCode.W)
local a = UIS:IsKeyDown(Enum.KeyCode.A)
local s = UIS:IsKeyDown(Enum.KeyCode.S)
local d = UIS:IsKeyDown(Enum.KeyCode.D)
print(q, w, a, s, d)
-- Creating BP
local function createBP(bpDir)
-- Instantiating
local bp = Instance.new("BodyPosition", root)
bp.MaxForce = Vector3.new(25000, 0, 25000)
bp.P = (10000000/15)*dashDist
bp.D = (40000/25)*(dashDist*0.75)
-- Setting BodyPosition Position
local position = root.Position + bpDir*dashDist
bp.Position = position
-- Returning
return bp
end
-- Flashing
local function flash(t) -- t is time to take
-- Creating Particle Part
local part = Instance.new("Part")
part.CFrame = root.CFrame
part.Anchored = true
part.Transparency = 1
part.CanCollide = false
part.CanQuery = false
part.CanTouch = false
part.Parent = workspace
-- Cloning Particle
local att = Instance.new("Attachment", part)
local particle = script.Teleport:Clone()
particle.Parent = att
Debris:AddItem(part, particle.Lifetime.Max)
-- Making Invisible
local parts = {}
for i, part in pairs(char:GetDescendants()) do
if part:IsA("BasePart") and part.Transparency == 0 then
part.Transparency = 1
table.insert(parts, part)
end
end
wait(t)
-- Disabling Particle
particle.Enabled = false
-- Making Visible
for i, part in pairs(parts) do
part.Transparency = 0
end
end
-- Checking Input
if q and d then -- Right
lastDash = os.clock()
-- Dashing
dDash:Play()
local bp = createBP(root.CFrame.RightVector)
-- Cleaning Up
local length = dDash.Length; if dDash.Length == 0 then length = 0.5 end
Debris:AddItem(bp, length)
-- Flashing
flash(length)
elseif q and a then -- Left
lastDash = os.clock()
-- Dashing
aDash:Play()
local bp = createBP(root.CFrame.RightVector*-1)
-- Cleaning Up
local length = aDash.Length; if aDash.Length == 0 then length = 0.5 end
Debris:AddItem(bp, length)
-- Flashing
flash(length)
elseif q and w then -- Front
lastDash = os.clock()
-- Dashing
wDash:Play()
local bp = createBP(root.CFrame.LookVector)
-- Cleaning Up
local length = wDash.Length; if wDash.Length == 0 then length = 0.5 end
Debris:AddItem(bp, length)
-- Flashing
flash(length)
elseif q and s then -- Back
lastDash = os.clock()
-- Dashing
sDash:Play()
local bp = createBP(root.CFrame.LookVector*-1)
-- Cleaning Up
local length = sDash.Length; if sDash.Length == 0 then length = 0.5 end
Debris:AddItem(bp, length)
-- Flashing
flash(length)
end
end)
while true do
wait()
local keys = UIS:GetKeysPressed()
print(#keys)
end