I need to check if player clicked in one time button "w or d or s or a" and "space" at one time.
✓ ANSWER ACCEPTED
How to check if player clicked keyboard button?
3 answers
✓ Accepted answer
I hope you meant these buttons but not the direct expression.
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.W or Enum.KeyCode.A or Enum.KeyCode.S or Enum.KeyCode.D or Enum.KeyCode.Space then
print("A key is being pushed down! Key:",input.KeyCode)
-- Your choice.
end
end)
If you want a WSADSpace movement then I prefer this:
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.UserInputType.W then
--W
elseif input.KeyCode == Enum.KeyCode.A then
--A
elseif input.KeyCode == Enum.KeyCode.S then
--S
elseif input.KeyCode == Enum.KeyCode.Dthen
--D
elseif input.KeyCode == Enum.KeyCode.Space then
--Space Bar
end
if gameProcessed then
print("\tObserved this input!")
else
print("\tDidn't observe this input!")
end
end)
Do something like
local UIS= game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
-- code here
end
end)
This is not a request site. At least make an effort by doing research and putting it into a Script first. Then if you have an error, you can come to this site. Anyways, the way to do this is use UserInputService.
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.W or Enum.KeyCode.A or Enum.KeyCode.S or Enum.KeyCode.D and Enum.KeyCode.Space then
-- whatever happens when the player hits those keys
end
end)
Hope this helps!
2 comments
0
Thanks you, I will test it right now.
0
Nothing works...
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Nothing works...