If the “Key Pressed!” message is not being displayed, then there may be an issue with the if statement’s condition. However, it definitely looks correct. Going up a line, we look at InputService.InputBegan:Connect(function()), but this also appears correct. If all three lines of code here are correct, then the issue must be earlier in the code.
The next bit of code before this input service code regards the Changed event of Humanoids. Looking at the content here, there appears to be no issue with the syntax and logic either, so there shouldn’t be an issue here.
Finally, the last portion of code before both event connections are your variables. When the last portion of code to look at regards variables, there is a high chance that the code has either errored there or is not getting through the variables. You make no mention of errors in the output, so errors are probably not the issue. That leaves the issue that your variables are probably not successfully continuing. The number 1 culprit of such a situation is the WaitForChild() function. In the API for this function, it is described that a script will yield at a WaitForChild(child) function call until the child parameter is found. This means that if child is never found, then the script will never go past this point. Your variables Torso, Humanoid, DiveEvent, and Player.CharacterAdded:wait() all yield the script at their respective points if the child being waited for (or, in the case of the CharacterAdded event, the event being fired itself) is never found. Therefore, this is most likely where the issue in your code is.
You can verify this by putting print("All variables loaded.") right under the last variable you created. If this print statement is never reached, then clearly a child is never found (or the CharacterAdded event is never fired). You can further narrow down exactly which one is not working by doing the following:
local Player = ...
local Character = Player.Character or Player.CharacterAdded:wait() -- I'm not sure if this is true, but lower case "wait" could be an issue. I suggest following Roblox's current naming convention and capitalizing the 'w'.
print("Character found!") -- CONFIRMATION that the player's character is obtained
local Torso = Character:WaitForChild("Torso")
print("Torso found!") -- CONFIRMATION that the torso is found
local Humanoid = Character:WaitForChild("Humanoid")
print("Humanoid found!") -- CONFIRMATION that the humanoid is found
local InputService = ...
local DiveEvent = game.ReplicatedStorage.Functions.Character:WaitForChild("Diving")
print("Dive event found!")
local Diving = ...
The location and values of each print statement is a checkpoint system that indicates how far the code manages to get. If, after running the code, you see in the output the following and only the following messages:
Character Found!
Torso found!
then this means that your code only managed to reach the print("Torso found!") line, but not the print("Humanoid found!") line. What line of code is between those two print statements? The WaitForChild("Humanoid"). This would mean that for some reason Humanoid is never found. How you resolve the issue from here is up to you.
If it is not the case that your variables are the issue, then I have misread the code somewhere (I haven’t tried running your code in Studio). In that case, add a print statement that is directly under InputService.InputBegan but before if Input.Keycode to ensure that the InputBegan event is at least firing.
A final note about WaitForChild(child, timeout): there are actual two parameters you can put for this function. The second parameter which I have called timeout is optional. If you do give it a value, it must be a number. The purpose of this parameter is to essentially quit WaitForChild() after timeout seconds has passed. For instance, MyPart:WaitForChild("BillboardGuiii", 3) will yield the script at this line and (if a child named “BillboardGuiii” is never found after 3 seconds) resume the script. If child is never found and timeout seconds has passed, then nil is returned.