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: Loop stopping with key method

Previous Thread :: Next Thread 
andytheepic is not online. andytheepic
Joined: 20 May 2011
Total Posts: 83
06 Feb 2014 07:57 PM
So I have made a script that has a loop and a bar drain that activates when I hold a button. Though when I release the button it keeps playing the loop. I want the bar to stop draining when I release the key I press. I need to know how to break loops on KeyUp.
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
06 Feb 2014 07:59 PM
keydown
keyisdown = true
repeat whatever until keyisdown = false

keyup
keyisdown = false
Report Abuse
andytheepic is not online. andytheepic
Joined: 20 May 2011
Total Posts: 83
06 Feb 2014 08:06 PM
Not very helpful. Can you please like describe, your just telling random stuff that is not even in the right case.
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
06 Feb 2014 08:09 PM
i just gave you a perfect outline for your script
Report Abuse
andytheepic is not online. andytheepic
Joined: 20 May 2011
Total Posts: 83
06 Feb 2014 08:22 PM
I already have a script, I just need a way to stop the loop when keyup.
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
06 Feb 2014 08:24 PM
at the end of your loop do a keyup function, check if it's the right key if it is do

break
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
06 Feb 2014 08:32 PM
localscript plz


down = true
player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
if key == "y" and down = true then
prunt("y is up")
down = true
mouse.KeyUp:connect(function(key)
if key == "y" then
down = false
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
06 Feb 2014 08:33 PM
down = true
player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
if key == "y" and down = true then
prunt("y is up")
down = true
mouse.KeyUp:connect(function(key)
if key == "y" then
down = false
end
end
end)
end)


:o
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
06 Feb 2014 08:39 PM
kev what

if anything

down = false
player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
if key == "y" and not down then
prunt("y is down")
down = true
repeat dostuff() wait() until not down
end
end)
mouse.KeyUp:connect(function(key)
if key == "y" then
down = false
end)

or do this

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

mouse.KeyDown:connect(function(key)
if key == "y" then
prunt("y is down")
while true do
wait()
dostuff()
mouse.KeyUp:connect(function(ke)
if ke == "y" then
break
end
end)
end
end)
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
06 Feb 2014 08:40 PM
down = true
player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
if key == "y" and down == true then
print("y is up")
down = true
mouse.KeyUp:connect(function(key)
if key == "y" then
down = false
end
end
end)
end)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Feb 2014 08:41 PM
I like this way the best:

local player = Game.Players.LocalPlayaer
local mouse = player:GetMouse()
local down = false

mouse.KeyDown:connect(function(key) if k == "y" then down = true end end)
mouse.KeyUp:connect(function(key) if k == "y" then down = false end end)

while wait() do
if down then
--etc
end
end
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
06 Feb 2014 08:42 PM
lolz
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
06 Feb 2014 08:43 PM
problem with that is that you're unnecessarily making the computer check every wait(). much better to do my first solution
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
06 Feb 2014 08:44 PM
also i've actually had problems with that method
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Feb 2014 08:45 PM
while loops don't lag if you do nothing but wait. Your way is glitchy, if someone plugs in two keyboards then your way will screw everything up. It's better to be safe.
Report Abuse
andytheepic is not online. andytheepic
Joined: 20 May 2011
Total Posts: 83
06 Feb 2014 08:46 PM
None of these work for the script I made.
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
06 Feb 2014 08:55 PM
give us the script?
Report Abuse
andytheepic is not online. andytheepic
Joined: 20 May 2011
Total Posts: 83
06 Feb 2014 09:07 PM
I ma remaking my scripts to help better adjust with my stuff. I have values and gui and stuff and your scripts can't integrate it. Thanks for all your help guys.
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
06 Feb 2014 09:09 PM
give us your script and let us do it for you...
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