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
 

Why is this?

Previous Thread :: Next Thread 
selena13524 is not online. selena13524
Joined: 18 Jan 2010
Total Posts: 260
20 Sep 2013 10:34 PM
local cur = game.Players.LocalPlayer.PlayerGui.StatsGui.Main.CBar.Cur
input.KeyDown:connect(function(key)

while key == "q" do
wait(0.2)
cur.Text = cur.Text - 5
end

Even when I'm not holding down the "q", it still takes away 5 from cur.Text.
Anyone know why? Please.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
20 Sep 2013 10:56 PM
Because 'key' is never changed. Every time the event fires, it runs that function again separately.
One method of accomplishing what you want is to throw in the currently-down keys into a table:

local keys = {}

input.KeyDown:connect(function(key)
keys[key] = true
while (keys[key]) do
Wait(0.2)
cur.Text = (cur.Text - 5)
end
end)

input.KeyUp:connect(function(key)
keys[key] = nil
end)
Report Abuse
selena13524 is not online. selena13524
Joined: 18 Jan 2010
Total Posts: 260
20 Sep 2013 11:30 PM
Thank you. But can anyone please explain to me where I should put my "q"? Because it decreases with every key I press. I just don't understand tables very well. Help. ;-;
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
21 Sep 2013 12:26 AM
I'll be honest, I dont understand crazy's code... I bet it works fine, but I dont understand it either O_O

So I'll suggest an alternative method.

local pressed = false

input.KeyDown:connect(function(key)
if string.lower(key) == 'q' then
pressed = true
end
while (pressed) do
Wait(0.2)
cur.Text = (cur.Text - 5)
end
end)

input.KeyUp:connect(function(key)
if key == 'q' then pressed = false
end
end)

Try this one?
Report Abuse
selena13524 is not online. selena13524
Joined: 18 Jan 2010
Total Posts: 260
21 Sep 2013 12:35 AM
:P Will do, thank 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