|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
| |
|