#key detection
51 messages · Page 1 of 1 (latest)
** You are now Level 3! **
user input service
i know how to check the current key but not the previous key
gimme a minute
okay
wdym
if Input.KeyCode == Enum.Key.Code.F then
for example if a player pressed A then changed it to D
i want two variable to keep track of them
currentkey would be D and previous key would be A
.
i got it
** You are now Level 10! **
basically
yes
it only stores current key, not previous
make a variable for the current key
then
make another variable
called like prevkey or something
set the prevkey
to the currentkey
before the currentkey gets set to the key you currently pressing
basically
previousKey = currentkey
currentkey = input.KeyCode
local d = false
local a = false
UserInputService.InputBegan:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.D then
d = true
elseif inp.KeyCode == Enum.KeyKode.A then
a = true
end
end)
UnserInputService.InputEnded:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.D then
d = false
elseif inp.KeyCode == Enum.KeyKode.A then
a = false
end
end)
** You are now Level 4! **
i dont really know what you mean but thats the script from what i understand
he knows how to detect the current key
he just needs the one before it
he wants the previous key to be stored?
just use this
yeah
ahhh
I get it
so he probably wants to create somethin like ctrl + C right
anyway
but that would make the previousKey change to currentkey
or am i wrong
nah
no
because
its placed before it
so basically
if currentkey is nil
then previouskey will become nil but then the currentkey will change to a
or whatever u press
so then previouskey will become a but currentkey will become something else
cause code runs from top to bottom
not all at once