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.

5 comments
You need to explain what you've done. Just posting some code wouldn't help anyone learn..
Well I understood completely.
It works! :D
@MrLegoman900 I am but I decide to most it before explain it so people can see I'm answering the question so they don't have to. Then I edit it and explain how it works.
Mouse.KeyDown was deprecated and the description says "This member exists for compatibility and should not be used in new scripts.", you may want to consider using UserInputService instead to check for key events