UserInputService

1

  • only works as a localscript
StarterPlayer/StarterPlayerScripts/LocalScript
local UIS = game:GetService("UserInputService")

function doIt(input, gameProcessedEvent)
  if input.KeyCode == Enum.KeyCode.A then
    print("A pressed!")
  end
end

UIS.InputBegan:Connect(doIt)

You can use the code above to delete a part for example

StarterPlayer/StarterPlayerScripts/LocalScript
local UIS = game:GetService("UserInputService")

function doIt(input, gameProcessedEvent)
    if input.KeyCode == Enum.KeyCode.R then
        local Bomb = game.Workspace:FindFirstChild("Bomb")
        if Bomb then
            Bomb:Destroy()
        end
    end
end

UIS.InputBegan:Connect(doIt)

https://developer.roblox.com/en-us/api-reference/class/UserInputService

  • 0 posts
  • 0 subtopics
  • 3 months ago by vince