Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if player press a keyboard key while touching a brick?

Asked by 6 years ago

How do I check if a player press for example the button R while being in (touching) a part?

0
use UserInputService inside a touched event. Audiimo 105 — 6y
0
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? GottaHaveAFunTime 218 — 6y
0
how do i use userinputservice inside a touched event realmadrid02 8 — 6y
0
Do your normal touched event then search up userinputservice on wiki or youtube and put the code inside your event Audiimo 105 — 6y
0
thanks realmadrid02 8 — 6y

1 answer

Log in to vote
0
Answered by
Tomstah 401 Moderation Voter
6 years ago

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.

  1. 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)

  2. 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.

  3. A block below or surrounding the player that runs :GetTouchingParts() that's welded to the character. Rest is the same as number 2.

Ad

Answer this question