So i want something to happen then a certain key is pressed.
So far i have this
function keyDown(key) if key == "a" then end end
But it does not seem to work
The reason why it doesn't work is because you haven't called the function or even set up event.We also need to get the Player's mouse so I suggest using a Local Script.
I will comment you through each line of code.
local Player = game.Players.LocalPlayer-- Getting the Local Player local Mouse = Player:GetMouse()-- Getting the Local Player's mouse local Character = Player.Character-- Getting the Local Player's Character Mouse.KeyDown:connect(function(Key)--This function fire's the KeyDown event everytime a key has been pressed if Key == "a" then--This -- If Statement checks if the "a" key has been pressed if it has it continues. print(Key.." Has been pressed")-- This tell us "a" key has been pressed -- Code, Example will be below. Character.Humanoid.WalkSpeed = 25-- Change the Character's WalkSpeed. end end)
Tip: Set up Variables like I have done which saves you a lot of time! Since you don't have to type as much!
Helpful Links: KeyDown Local Players Parameters