This script from a wiki article I'm copying does not make me double jump?
Hello, I was trying to make my own copy of this wiki article by typing it up myself instead of copy/paste, however, it doesn't work! It doesn't show an error in the output, but the player cannot use the double jump ability.
Here is my code:
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local localPlayer = game.Players.LocalPlayer |
06 | local canDoubleJump = false |
07 | local hasDoubleJumped = false |
09 | local TIME_BETWEEN_JUMPS = 0.2 |
10 | local DOUBLE_JUMP_POWER_MULTIPLIER = 2 |
12 | function onJumpRequest() |
13 | if not character or not humanoid or not character:IsDescendantOf(workspace) or |
14 | humanoid:GetState() = = Enum.HumanoidStateType.Dead then |
18 | if canDoubleJump and not hasDoubleJumped then |
19 | hasDoubleJumped = true |
20 | humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER |
21 | humanoid:ChangeState(Enum.HumanoidStateType.Jumping) |
25 | local function characterAdded(newCharacter) |
26 | character = newCharacter |
27 | humanoid = newCharacter:WaitForChild( "Humanoid" ) |
28 | hasDoubleJumped = false |
30 | oldPower = humanoid.JumpPower |
32 | humanoid.StateChanged:connect( function (old, new) |
33 | if new = = Enum.HumanoidStateType.Landed then |
35 | hasDoubleJumped = false |
36 | humanoid.JumpPower = oldPower |
37 | elseif new = = Enum.HumanoidStateType.Freefall then |
38 | wait(TIME_BETWEEN_JUMPS) |
44 | if localPlayer.Character then |
45 | characterAdded(localPlayer.Character) |
48 | localPlayer.CharacterAdded:connect(characterAdded) |
49 | UserInputService.JumpRequest:connect(onJumpRequest) |
And for comparison, the Wiki article code:
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local localPlayer = game.Players.LocalPlayer |
06 | local canDoubleJump = false |
07 | local hasDoubleJumped = false |
09 | local TIME_BETWEEN_JUMPS = 0.2 |
10 | local DOUBLE_JUMP_POWER_MULTIPLIER = 2 |
12 | function onJumpRequest() |
13 | if not character or not humanoid or not character:IsDescendantOf(workspace) or |
14 | humanoid:GetState() = = Enum.HumanoidStateType.Dead then |
18 | if canDoubleJump and not hasDoubleJumped then |
19 | hasDoubleJumped = true |
20 | humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER |
21 | humanoid:ChangeState(Enum.HumanoidStateType.Jumping) |
25 | local function characterAdded(newCharacter) |
26 | character = newCharacter |
27 | humanoid = newCharacter:WaitForChild( "Humanoid" ) |
28 | hasDoubleJumped = false |
30 | oldPower = humanoid.JumpPower |
32 | humanoid.StateChanged:connect( function (old, new) |
33 | if new = = Enum.HumanoidStateType.Landed then |
35 | hasDoubleJumped = false |
36 | humanoid.JumpPower = oldPower |
37 | elseif new = = Enum.HumanoidStateType.Freefall then |
38 | wait(TIME_BETWEEN_JUMPS) |
44 | if localPlayer.Character then |
45 | characterAdded(localPlayer.Character) |
48 | localPlayer.CharacterAdded:connect(characterAdded) |
49 | UserInputService.JumpRequest:connect(onJumpRequest) |