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: KeyDown keeps running till I let go of button

Previous Thread :: Next Thread 
roblock59 is not online. roblock59
Joined: 30 Jul 2010
Total Posts: 155
04 Apr 2015 03:29 PM
Lets say if I hold down "c" the function keeps repeating till I let go how do i do this I got everything set up just need help with this x3.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
04 Apr 2015 03:31 PM
local UIS = game:GetService('UserInputService')

UIS.InputBegan:connect(function(inputObject, gameProcessedEvent)
if not gameProcessedEvent then
if inputObject.KeyCode == Enum.InputObject.C then
print('C why u should use UserInputService now?')
end
end
end)
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
04 Apr 2015 03:32 PM
down=false

mouse.KeyDown:connect(function(key)
if key:lower()=="c" then
down=true
repeat
print('hi')
until not down
end
end)

mouse.KeyUp:connect(function(key)
if key:lower()=="c" then
down=false
end
end)
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
04 Apr 2015 03:32 PM
UserInputService is a lot more efficient and I recommend using it.
Not to mention it's compatible with mobile.
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
04 Apr 2015 03:33 PM
you should use UserInputService but you want the mouse

mouse = game.Players.LocalPlayer:GetMouse()

holdingkey = false

mouse.KeyDown:connect(function(key)
if key == "c" then
holdingkey = true
while holdingkey do
--stuff
end
end
end)

mouse.KeyUp:connect(function(key)
if key == "c" then
holdingkey = false
end
end)
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
04 Apr 2015 03:35 PM
local UIS = game:GetService('UserInputService')
local pressing

UIS.InputBegan:connect(function(inputObject, gameProcessedEvent)
if not gameProcessedEvent then
if inputObject.KeyCode == Enum.InputObject.C then
pressing = true
while pressing do
print('C why u should use UserInputService now?')
wait(.2)
end
end
end
end)

UIS.InputEnded:connect(function(inputObject, gameProcessedEvent)
if not gameProcesedEvent then
if inputObject.KeyCode == Enum.InputObject.C then
pressing = false
print('u stopped pressing :)')
end
end
end)
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
04 Apr 2015 03:37 PM
lol im dumb

i messed up the Enum.

Here's a working version I tested:

local UIS = game:GetService('UserInputService')
local pressing

UIS.InputBegan:connect(function(inputObject, gameProcessedEvent)
if not gameProcessedEvent then
if inputObject.KeyCode == Enum.KeyCode.C then
pressing = true
while pressing do
print('C why u should use UserInputService now?')
wait(.2)
end
end
end
end)

UIS.InputEnded:connect(function(inputObject, gameProcessedEvent)
if not gameProcessedEvent then
if inputObject.KeyCode == Enum.KeyCode.C then
pressing = false
print('u stopped pressing :)')
end
end
end)
Report Abuse
roblock59 is not online. roblock59
Joined: 30 Jul 2010
Total Posts: 155
04 Apr 2015 03:40 PM
thanks @amanda
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