I have a module script, and I want to know if the P key is JUST pressed. Not held down or anything. But how would I set that in a module?
For example, if you want to know if a key was just pressed in a while loop while it’s still running without using UserInputService.InputBegan outside of the loop.
That is fine and all, but I want to find out if they pressed the button inside a loop, not outside. Something like Godot’s method would be appreciated.
local USI = game:GetService("UserInputService")
local ifKeyboardP = {
"",
USI.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.P then
print("Player pressed P")
end
end)
}
return ifKeyboardP
And this in your normal script
local module = require(game.ServerScriptService.ModuleScript) --Change this to the location of your module script
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.P then
print(module[1])
end
end)
When it prints unfortuantly it will just print a blank message before that but I don’t think that’s too much of a problem. Also I could not get the USI to only work in the loop but it’s the only way I know how to do it.