How do I check if a player press for example the button R while being in (touching) a part?
How to check if player press a keyboard key while touching a brick?
1 answer
For this you'll have to make a UIS (User Input Service) event that triggers when a client provides input. After the event triggers, you need to write a conditional to see if the the button you want was pressed. If the conditional passes, then there's a few methods to see if they're touching the brick.
Distance from the player from the brick. Simply use Pythagorean Theorem and detect how far the block is from the humanoid, typically by torso or head. If it isn't within a certain range, it fails. Pros to this is it would be more efficient and would fail less, but by doing so it could be triggered when their humanoid isn't actually touching. (This is probably the best way)
A block surrounding the brick you want to touch runs :GetTouchingParts() after doing so check to see if any parts touching are descendants of a player-character.
A block below or surrounding the player that runs :GetTouchingParts() that's welded to the character. Rest is the same as number 2.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
use UserInputService inside a touched event.
You have to use an if statement. So like If part.Touched and (I dont know the script for keyboard presses off the top of my head so yeah) KeyPressed == "R" then... And you know?
how do i use userinputservice inside a touched event
Do your normal touched event then search up userinputservice on wiki or youtube and put the code inside your event
thanks