0

# Any easier way to write this?

Zerio920 285
7 years ago

The Wiki says I can record key presses in a table to determine whether the key is being held or not, so something like

local keys = {}

mouse.KeyDown:connect(function(key)
keys[key] = true
end)
mouse.KeyUp:connect(function(key)
keys[key] = nil
end)

while wait(0.1) do
if keys["q"] and Tool.Val.Value > 0 then
Tool.Val.Value = Tool.Val.Value - 5
elseif keys["e"] and Tool.Val.Value < 200 then
Tool.Val.Value = Tool.Val.Value + 5
end
end


However, I'd also like to differentiate between a key press and someone holding down the key, and while the script is effective enough at doing that, it only checks for key presses every 1/10th of a second, so anytime someone pushes a key in that 10th of a second it won't count. It's minor, yeah, but I'd really like to find a more concise method of determining keystrokes from key presses.

You can make the loop go faster if you want. If you leave out the argument in wait() it will delay the script the minimum amount of time it can, about a 30th of a second.