Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help with key pressed tool?

Asked by
Zyleak 70
9 years ago

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

0
Well you dont have it do anything. BinaryResolved 215 — 9y
0
If you want it to see if it work. And im pretty sure it will. On line 3 put a print() function. So it will show that when you press a BinaryResolved 215 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

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

0
Use UserInputService instead of KeyDown EzraNehemiah_TF2 3552 — 9y
Ad

Answer this question