generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Key press detection

Previous Thread :: Next Thread 
jbn011 is online. jbn011
Joined: 30 Aug 2010
Total Posts: 479
26 Jul 2016 01:45 PM
How would you do detect if the player presses a key while seated?

For example, detecting if the key Q is held down/pressed.
Report Abuse
DeGames is not online. DeGames
Joined: 08 Sep 2012
Total Posts: 1028
26 Jul 2016 01:46 PM
http://wiki.roblox.com/index.php?title=Keyboard_input
Report Abuse
jbn011 is online. jbn011
Joined: 30 Aug 2010
Total Posts: 479
26 Jul 2016 01:52 PM
How would you connect that though with a seat?
Report Abuse
QuantumPhoton is not online. QuantumPhoton
Joined: 19 Jan 2016
Total Posts: 309
26 Jul 2016 01:52 PM
Teleport them to the seat, and active "sit" in humanoid? I dont really know
Report Abuse
DeGames is not online. DeGames
Joined: 08 Sep 2012
Total Posts: 1028
26 Jul 2016 01:57 PM
if Humanoid.sit

and i found someone say something like

"function oAdd(object)
--stuff
end
function oRem(object)
--stuff
end
script.Parent.ChildAdded:connect(oAdd)
script.Parent.ChildRemoved:connect(oRem)

Put that script inside the seat"
Report Abuse
Naxxanar is not online. Naxxanar
Joined: 13 Jun 2012
Total Posts: 709
26 Jul 2016 02:07 PM
bleh idk

never tried it
but im too lazy and will just write what i would think would work

put this in a client sided script:

--Made by Naxxanar

local Players = Game:GetService('Players');
local Player = Players.LocalPlayer;
repeat Wait(0) until Player.Character;
local Character = Player.Character;
local Humanoid = Character.Humanoid;

local Sit = false;

local UserInputService = Game:GetService('UserInputService');

UserInputService.InputBegan:connect(function(Input, GPE)
if not GPE then
if Input.KeyCode == Enum.KeyCode.Q then
if Sit == true then
warn('Available: Seated & pushed');
else
warn('Unavailable: Unseated & pushed');
end
end
end
end)

Humanoid.Seated:connect(function()
if Sit == false then
Sit = true
print('Seated');
end
end)

Humanoid.Jumping:connect(function()
if Sit == true then
Sit = false
print('Unseated');
end
end) Enum.KeyCode.Q then
if Sit == true then
print('Pressed');
else
print('Unavailable');
end
end
end
end)


Report Abuse
Naxxanar is not online. Naxxanar
Joined: 13 Jun 2012
Total Posts: 709
26 Jul 2016 02:09 PM
unfortunately the text mashed together so maybe like this


--Made by Naxxanar

local Players = Game:GetService('Players');
local Player = Players.LocalPlayer;
repeat Wait(0) until Player.Character;
local Character = Player.Character;
local Humanoid = Character.Humanoid;

local Sit = false;

local UserInputService = Game:GetService('UserInputService');

UserInputService.InputBegan:connect(function(Input, GPE)
if not GPE then
if Input.KeyCode == Enum.KeyCode.Q then
if Sit == true then
warn('Available: Seated & pushed');
else
warn('Unavailable: Unseated & pushed');
end
end
end
end)


Humanoid.Seated:connect(function()
if Sit == false then
Sit = true
print('Seated');
end
end)


Humanoid.Jumping:connect(function()
if Sit == true then
Sit = false
print('Unseated');
end
end)


Report Abuse
jbn011 is online. jbn011
Joined: 30 Aug 2010
Total Posts: 479
26 Jul 2016 02:17 PM
I just tried it and nothing seemed to happen
Report Abuse
jbn011 is online. jbn011
Joined: 30 Aug 2010
Total Posts: 479
26 Jul 2016 02:20 PM
There were no errors either
Report Abuse
Naxxanar is not online. Naxxanar
Joined: 13 Jun 2012
Total Posts: 709
26 Jul 2016 02:31 PM
Basically it does what you said: If the player is seated, and they press Q, it will operate functionally, but if they are unseated and press Q, nothing happens

If you are able to script yourself, you should be able to make additional things.


Report Abuse
Naxxanar is not online. Naxxanar
Joined: 13 Jun 2012
Total Posts: 709
26 Jul 2016 02:32 PM
>For example, detecting if the key Q is held down/pressed.

Open the Output and press Q while seated and unseated on a seat and you'll see


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image