Hello I wonder how I can make a keybind while pressing 2 keys at the same time. Such as Shift+P for Freecam, how can I do that?
1 Like
You could check if a player is pressing both keys by using 2 seperate variables
local UIS = game:GetService("UserInputService")
local isPressingP = false
local isPressingShift = false
UIS.InputBegan:Connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.P then
isPressingP = true
end
if key.KeyCode == Enum.KeyCode.LeftShift then
isPressingShift = true
end
end)
UIS.InputEnded:Connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.P then
isPressingP = false
end
if key.KeyCode == Enum.KeyCode.LeftShift then
isPressingShift = false
end
end)
if isPressingP and isPressingShift then
--Both keys are being pressed at the same time
end
lmk if this is what you need
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function()
if uis:IsKeyDown(Enum.KeyCode.LeftShift) == true and uis:IsKeyDown(Enum.KeyCode.P) == true then
--Code here
end
end
3 Likes
Sorry for long delay, but yeah this worked, thanks a lot!
1 Like
This script will check only once if player holding these keys. You should check everytime.
You mean like put it into a loop to constantly check?
Yes.
while task.wait() do
if isPressingP and isPressingShift then
end
end
Putting it in a while loop is worse than a inputbegan function, you’d only need to fire it when pressing a key
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.