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: How do I incorporate the keyboard into Lua?

Previous Thread :: Next Thread 
typicalTOPHAT is not online. typicalTOPHAT
Joined: 25 Feb 2013
Total Posts: 66
19 Feb 2014 09:51 PM
Let's say you hit the "K" key. Woah, that part just became red! But how?
Report Abuse
typicalTOPHAT is not online. typicalTOPHAT
Joined: 25 Feb 2013
Total Posts: 66
19 Feb 2014 09:52 PM
b1
In other words, I want to make a Roblox Punch-Out port, and need to use the keyboard.
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
19 Feb 2014 09:57 PM
Put this in a localscript and put the script into a textbutton and put the button into a gui

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Button = script.Parent

Mouse.KeyDown:connect(function(Key)
if Key == "k" then
game.Workspace.Part.BrickColor = BrickColor.new("Bright red")
end)
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
19 Feb 2014 09:59 PM
Actually,the localscript he posted,can be put directly into startergui:P
StarterGui
-LocalScript
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
19 Feb 2014 10:00 PM
also
@crazy,u forgot an end
Report Abuse
Computermaster01 is online. Computermaster01
Joined: 29 May 2012
Total Posts: 369
19 Feb 2014 10:04 PM
Use:


:keydown

Like this:

Brick = -- Put the link to the Brick here.
Color = ("Red") --Replace Red with the color you want.

function onKeyDown(key)
if key == ("K") then
Brick.BrickColor = BrickColor.new(Color)
end
end

mouse.KeyDown:connect(onKeyDown)
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
19 Feb 2014 10:08 PM
Oops forgot the end.
Report Abuse
typicalTOPHAT is not online. typicalTOPHAT
Joined: 25 Feb 2013
Total Posts: 66
19 Feb 2014 10:12 PM
None of these work, although they look like they should. Also, don't orientate your scripts to make a part red, keep it generic. That was just an example.
Report Abuse
typicalTOPHAT is not online. typicalTOPHAT
Joined: 25 Feb 2013
Total Posts: 66
19 Feb 2014 10:16 PM
B2
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
19 Feb 2014 10:20 PM
@computer,
Colors don't have parentheses around them.
Also there are no color called Red
Report Abuse
typicalTOPHAT is not online. typicalTOPHAT
Joined: 25 Feb 2013
Total Posts: 66
19 Feb 2014 10:24 PM
You guys are missing the point.
Report Abuse
SnowyKirby is not online. SnowyKirby
Joined: 15 Jan 2013
Total Posts: 68009
19 Feb 2014 10:27 PM
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.MouseButton1Click(function(onClick)
mouse.KeyDown:connect(function(k)
if k:byte() == 107 then
game.Workspace.Part.BrickColor = BrickColor.new("Bright red")
end
end)
end)
Report Abuse
SnowyKirby is not online. SnowyKirby
Joined: 15 Jan 2013
Total Posts: 68009
19 Feb 2014 10:29 PM
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.MouseButton1Click:connect(function(onClick)
mouse.KeyDown:connect(function(k)
if k:byte() == 107 then
game.Workspace.Part.BrickColor = BrickColor.new("Bright red")
end
end)
end)

sorry for got one thing
Report Abuse
SnowyKirby is not online. SnowyKirby
Joined: 15 Jan 2013
Total Posts: 68009
19 Feb 2014 10:33 PM
LOL MESSED UP

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(k)
if k:byte() == 107 then
game.Workspace.Part.BrickColor = BrickColor.new("Bright red")
end
end)
Report Abuse
typicalTOPHAT is not online. typicalTOPHAT
Joined: 25 Feb 2013
Total Posts: 66
19 Feb 2014 10:35 PM
Thanks so much!
Report Abuse
SnowyKirby is not online. SnowyKirby
Joined: 15 Jan 2013
Total Posts: 68009
19 Feb 2014 10:36 PM
did it work?
Report Abuse
typicalTOPHAT is not online. typicalTOPHAT
Joined: 25 Feb 2013
Total Posts: 66
19 Feb 2014 10:39 PM
Yes, but it would help if you could explain the script. I am learning Lua, and this would help a lot.
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
19 Feb 2014 11:10 PM
Here is how it works:

local player = game.Players.LocalPlayer --get the player
local mouse = player:GetMouse() --get the player's mouse/keyboard

mouse.KeyDown:connect(function(k) --when the player presses a key, execute the function. 'k' is the key they pressed
if k:byte() == 107 then --if the byte of the key pressed is 107 (k's code) then NOTE: you could also do if k == "k" then
Workspace.Part.BrickColor = BrickColor.new("Bright red") --change the color
end
end)
Report Abuse
Crazy010517 is not online. Crazy010517
Joined: 17 Sep 2011
Total Posts: 1161
19 Feb 2014 11:24 PM
Isn't that like exactly what I wrote...?
Report Abuse
typicalTOPHAT is not online. typicalTOPHAT
Joined: 25 Feb 2013
Total Posts: 66
20 Feb 2014 02:17 PM
Crazy, I have no idea why yours didn't work. Maybe you used a different method, and messed up somewhere? Also, where "k"'s code is 107, where can I find the codes for other keys?
Report Abuse
jd678 is not online. jd678
Joined: 18 Apr 2008
Total Posts: 11529
20 Feb 2014 02:37 PM
you dont have to use a byte code


--LocalScript
Brick = Workspace:FindFirstChild("Brick") -- the brick you want to change to red
Mouse = game.Players.LocalPlayer:GetMouse()

Mouse.KeyDown:connect(function(Key)
if Key == "k" then
Brick.BrickColor = BrickColor.new("Bright red")
end
end)

Report Abuse
jd678 is not online. jd678
Joined: 18 Apr 2008
Total Posts: 11529
20 Feb 2014 02:38 PM
' NOTE: you could also do if k == "k" then '

I should prolly learn to read
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