I'm having a problem when
1 | if key = = "d" then |
2 | dir = dir + 1 |
3 | end |
this function happens i want it to hold not only tap it once and i'm having trouble with that basically what i'm trying to do is make a loop when its pressed and when its released the loop ends.
If your going to use Keydown()
then I recommend you use a LocalScript since it a lot easier to access the Player/Character using local script.
01 | Player = game.Players.LocalPlayer |
02 | Mouse = Player:GetMouse() |
03 |
04 | TurnD = false |
05 | Mouse.KeyDown:connect( function (key) -- Parameter |
06 | if key:lower() = = "f" then --This checks if the lowercase letter "f" has been clicked" if it has it continues the script |
07 | TurnD = not TurnD -- Changes the TurnD to false and true.It works like this: It check value/boolean if its false it turns it true if its true it turns it false. |
08 | print (TurnD) |
09 | while TurnD = = true do --This checks if TurnD is true if it is then it starts the while true loop. |
10 | --Code |
11 | wait( 1 ) |
12 | if TurnD = = false then -- If TurnD is false then it breaks the loop |
13 | break |
14 | end |
15 | end |
16 | end |
17 | end ) |