Copied code from roblox guide and doesn't work?
Asked by
5 years ago Edited 5 years ago
Just copied the code and everything from this guide https://developer.roblox.com/en-us/articles/Double-Jumping
It just doesnt work at all. I have no idea whats wrong, but literally nothing happens. im new to dev in roblox so some help would be nice. thanks
if it helps this is the 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 |