I’m trying to make it so that the player can use left shift and the space button to preform a move in my game, but the issue is that this does not work at all.
I’m not sure how I’m supposed to solve the issue and make it so that when I hit both keys at the same time, I can preform the move.
Probably not the most effective way of doing this, but you can try this:
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gpe)
if gpe then
return
end
if uis:IsKeyDown(Enum.KeyCode.LeftShift) and uis:IsKeyDown(Enum.KeyCode.Space) then
--// code here
end
end)
@AmoraFolf is right, you don’t use and, but you use commas, it’s the better way, but his scritp only needs an adjustment:
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gpe)
if gpe then
return
end
if uis:IsKeyDown(Enum.KeyCode.LeftShift, Enum.KeyCode.Space) then
--// code here
end
end)
local Combos = {
{
["InOrder"] = true,
["Repeating"] = false,
["MaxTimeBetweenKeys"] = 1, -- Disable with 0 or nil
["Keys"] = {Enum.KeyCode.LeftShift, Enum.KeyCode.Space},
["Function"] = function()
print("COMBO")
end,
}
}
local KeysDown = {}
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
if gameProcessed or input.UserInputType ~= Enum.UserInputType.Keyboard then return end
KeysDown[input.KeyCode] = os.clock()
end)
game:GetService("UserInputService").InputEnded:Connect(function(input, gameProcessed)
if gameProcessed or input.UserInputType ~= Enum.UserInputType.Keyboard then return end
KeysDown[input.KeyCode] = nil
end)
while wait() do
for _, ComboData in pairs(Combos) do
local lastClock = nil
local failed = false
for i, KeyCode in pairs(ComboData.Keys) do
local clock = KeysDown[KeyCode];
if clock ~= nil and (not ComboData.InOrder or lastClock == nil or lastClock < clock) then
if ComboData.MaxTimeBetweenKeys ~= nil and ComboData.MaxTimeBetweenKeys > 0 then
if lastClock and (clock - lastClock) > ComboData.MaxTimeBetweenKeys then
failed = true
break
end
end
lastClock = clock
else
failed = true
break
end
end
if not failed then
if not ComboData.Repeating then
KeysDown[ComboData.Keys[1]] = nil
end
ComboData.Function()
end
end
end
print("start of script")
local UIS = game:GetService("UserInputService")
local moveModule = require(game:GetService("ReplicatedStorage"):WaitForChild("Player"):WaitForChild("Moveset"))
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local state = moveModule.state
local moves = moveModule.moves
print("started")
UIS.InputBegan:Connect(function(input, gpe)
if not gpe then
if UIS:IsKeyDown(Enum.KeyCode.LeftShift, Enum.KeyCode.Space) then
moves("LJ")
elseif UIS:IsKeyDown(Enum.KeyCode.LeftControl) then
moves("Crouch")
elseif UIS:IsKeyDown(Enum.KeyCode.E) then
moves("Dive")
elseif UIS:IsKeyDown(Enum.KeyCode.LeftControl) and state == "Freefalling" then
moves("GP")
end
end
end)