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 » Scripting Helpers
Home Search
 

Re: Keyboard connection

Previous Thread :: Next Thread 
cheez55 is not online. cheez55
Joined: 19 Oct 2008
Total Posts: 646
13 Aug 2011 07:18 PM
What's the script connection line for a key press?
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
13 Aug 2011 07:19 PM
Mouse.KeyDown:connect(function(key)
if key == "t" then
print("Win")
end
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
13 Aug 2011 07:19 PM
Mouse.KeyDown:connect(function(key) end)
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
13 Aug 2011 07:20 PM
For some reason the keyboard is part of the mouse object, so you need to get the mouse first.

The only way to do that is through a tool or hopperbin's equipped and selected events (respectively).

script.Parent.Equipped:connect(function(mouse)

end)

From there, it's easy.

script.Parent.Equipped:connect(function(mouse)
mouse.KeyDown:connect(function(key) end)
mouse.KeyUp:connect(function(key) end)

end)

KeyDown and KeyUp events return what key was pressed/released. I used key in that script.

NOTE: Both of these events disconnect when the tool is unequipped.
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
13 Aug 2011 07:21 PM
I'll post how to get a global mouse :T
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
13 Aug 2011 07:21 PM
He only asked for the connection line... Not a book.
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
13 Aug 2011 07:22 PM
Doesn't hurt :C
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
13 Aug 2011 07:23 PM
function _G.GetMouse()
Tool = Instance.new("Tool")
Part = Instance.new("Part")
Part.Name = "Handle"
Part.Parent = Tool
Tool.Equipped:connect(function(Mouse)
_G["Mouse"] = Mouse
Tool.Parent = nil
end)
Tool.Parent = game.Players.LocalPlayer.Character
end
_G.GetMouse()
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
13 Aug 2011 07:24 PM
@1waffle1

Explaining it to them means they don't have to come back later if they don't understand something else.
Report Abuse
cheez55 is not online. cheez55
Joined: 19 Oct 2008
Total Posts: 646
13 Aug 2011 07:33 PM
@DarkMist on first reply: The output says that Mouse is a nil value. Is it supposed to be a variable?
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
13 Aug 2011 07:34 PM
...
cheez, thank you for indirectly validating why I gave you the full tutorial. Please read my post now.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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