This is a local script that is supposed to trigger one sever event if the key q is down and the other one if the key q is up, but all it does is activates the first event. Here is the script:
01 | wait() |
02 | local Players = game:GetService( "Players" ) |
03 | local Player = Players.LocalPlayer |
04 | local Character = Player.Character |
05 | local Mouse = Player:GetMouse() |
06 | local event = workspace.Events.DemonAbilities [ "Dark Nebula" ] |
07 | Enabled = true |
08 | ButtonDown = true |
09 |
10 | Mouse.KeyDown:Connect( function (key) |
11 | if Enabled = = false then return end |
12 |
13 |
14 | Mouse.KeyUp:Connect( function (key) |
15 |
Well first of all, I still don't have a clue what this means at all, but apparently KeyDown is "deprecated". It would be a good idea to try and figure out User Input Service instead, and get a hang of that, but here's an example of how I would do it with UIS.
01 | local players = game:GetService( "Players" ) |
02 | local player = players.LocalPlayer |
03 | local char = player.Character |
04 | local humanoid = char:WaitForChild( "Humanoid" ) |
05 |
06 | local UIS = game:GetService( "UserInputService" ) |
07 |
08 | UIS.InputBegan:Connect( function (key,isTyping) -- The key parameter gets filled with whatever key is pressed, and isTyping, or the second parameter is whether or not the player currently has the chat open. |
09 |
10 | if key.KeyCode = = Enum.KeyCode.Q and isTyping = = false then |
11 | -- Script for when key is pressed here. |
12 | end |
13 |
14 | end ) |
15 |
Also, with how your script is, I think the reason it didn't work is because you put the KeyUp inside of the KeyDown event. You would need to separate the two so they can both function properly. The KeyUp can only be activated after a key is pressed down and the key comes back up, so you don't need to put it in the other event.
Hope I helped!
Using the KeyDown event from the Mouse is deprecated. See this to know how deprecation effects your code.
You should instead use UserInputService to handle player input.
Example code of what it would look like in your case:
01 | --Get the service. |
02 | local UIS = game:GetService( "UserInputService" ) |
03 |
04 | --Make a function and use the first parameter for the input object. |
05 | function onPlayerInput(key, processed) |
06 | if key.KeyCode = = Enum.KeyCode.Q then |
07 | print ( "Letter Q was pressed!" ) |
08 | end |
09 | end |
10 |
11 | --Connect our function to input began. |
12 | UIS.InputBegan:Connect(onPlayerInput) |
Note that there is also ContextActionService that allows you to bind more keys and gamepads to functions.
Edit:
For checking if the Q key was released you would use the InputEnded event.