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:
wait() local Players = game:GetService("Players") local Player = Players.LocalPlayer local Character = Player.Character local Mouse = Player:GetMouse() local event = workspace.Events.DemonAbilities["Dark Nebula"] Enabled = true ButtonDown = true Mouse.KeyDown:Connect(function(key) if Enabled == false then return end Mouse.KeyUp:Connect(function(key) key = key:lower() if key == "q" then ButtonDown = false end end) key = key:lower() if key == "q" then Enabled = false if ButtonDown == true then event:FireServer() end end if ButtonDown == false then workspace.Events.DemonAbilities.darknebulaweldoff:FireServer() end wait(15) Enabled = true end)
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.
local players = game:GetService("Players") local player = players.LocalPlayer local char = player.Character local humanoid = char:WaitForChild("Humanoid") local UIS = game:GetService("UserInputService") 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. if key.KeyCode == Enum.KeyCode.Q and isTyping == false then -- Script for when key is pressed here. end end) UIS.InputEnded:Connect(function(key,isTyping) if key.KeyCode == Enum.KeyCode.Q and isTyping == false then -- Don't mind all the weird stuff with enum and crap, and just put the key you want after KeyCode. -- When key is let go of script here. end end)
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:
--Get the service. local UIS = game:GetService("UserInputService") --Make a function and use the first parameter for the input object. function onPlayerInput(key, processed) if key.KeyCode == Enum.KeyCode.Q then print("Letter Q was pressed!") end end --Connect our function to input began. 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.