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
 

Mouse.KeyDown help

Previous Thread :: Next Thread 
ASCIIaliens is not online. ASCIIaliens
Joined: 21 Apr 2011
Total Posts: 96
07 Feb 2015 09:22 PM
Mouse.KeyDown:connect(function(key)
if key == "d" then
repeat
num = num + 1
print(num)
wait(.5)
until key ~= "d"
end
end)

What this is supposed to do: While the user holds "d" on the keyboard, num is increased by 1 and is printed every .5 seconds. When the user lets go of "d" this should stop printing num and stop adding 1 to num.

What this actually does: When the user presses "d" num is printed and added to every .5 seconds, but when the user lets go of "d" it continues as if they were still holding it. Pressing "d" again will add to num and print num faster.

Help?
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
07 Feb 2015 09:25 PM
Mouse.KeyUp:connect(function()

end)

Join - http://www.roblox.com/My/Groups.aspx?gid=468509
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
07 Feb 2015 09:27 PM
Basically heres what you need


local keyPressed = false

Mouse.KeyDown:connect(function(key)
if key == "d" then
keyPressed = true
repeat
num = num + 1
print(num)
wait(.5)
until keyPressed == false
end
end)

Mouse.KeyUp:connect(function(key)
if key == "d" then
keyPressed = false
end)

Join - http://www.roblox.com/My/Groups.aspx?gid=468509
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
07 Feb 2015 09:27 PM
local keyPressed = false

Mouse.KeyDown:connect(function(key)
if key == "d" then
keyPressed = true
repeat
num = num + 1
print(num)
wait(.5)
until keyPressed == false
end
end)

Mouse.KeyUp:connect(function(key)
if key == "d" then
keyPressed = false
end end)


Join - http://www.roblox.com/My/Groups.aspx?gid=468509

Report Abuse
ASCIIaliens is not online. ASCIIaliens
Joined: 21 Apr 2011
Total Posts: 96
07 Feb 2015 09:41 PM
Thanks for the quick and helpful answer
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