✓ Accepted answer
You're using it correctly.
The problem is that the script runs this code once at the start of the game.
You could use a while loop to fix this,
local UIS = game:GetService("UserInputService")
while wait() do
if UIS:IsKeyDown(Enum.KeyCode.W) then
print("w")
end
end
But a better solution would be to use InputBegan.
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
print("w")
end
end)
This behaves differently than you may like, however, as it only prints once every time you press the W key, and it does not continue printing.
You could fix this by moving the while loop inside of the new function,
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
while wait() do
if UIS:IsKeyDown(Enum.KeyCode.W) then
print("w")
else
break;
end
end
end
end)
If you have any further questions let me know.
Thank you.
1 comment
just what i needed