I'm having a problem when
if key == "d" then dir = dir + 1 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.
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() TurnD = false Mouse.KeyDown:connect(function(key)-- Parameter if key:lower()=="f" then--This checks if the lowercase letter "f" has been clicked" if it has it continues the script 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. print(TurnD) while TurnD == true do--This checks if TurnD is true if it is then it starts the while true loop. --Code wait(1) if TurnD == false then-- If TurnD is false then it breaks the loop break end end end end)