How to make a double jump gamepass?
I want to make a double jump gamepass. Here is the script! Please Tell me where I made a mistake!
001 | local gamepassId = 12077225 |
002 | local mps = game:GetService( "MarketplaceService" ) |
004 | game.Players.PlayerAdded:Connect( function (plr) |
005 | if mps:UserOwnsGamePassAsync(plr.UserId,gamepassId) then |
007 | local UserInputService = game:GetService( "UserInputService" ) |
009 | local localPlayer = game.Players.LocalPlayer |
017 | local canDoubleJump = false |
019 | local hasDoubleJumped = false |
023 | local TIME_BETWEEN_JUMPS = 0.2 |
025 | local DOUBLE_JUMP_POWER_MULTIPLIER = 2 |
029 | function onJumpRequest() |
031 | if not character or not humanoid or not character:IsDescendantOf(workspace) or |
033 | humanoid:GetState() = = Enum.HumanoidStateType.Dead then |
041 | if canDoubleJump and not hasDoubleJumped then |
043 | hasDoubleJumped = true |
045 | humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER |
047 | humanoid:ChangeState(Enum.HumanoidStateType.Jumping) |
055 | local function characterAdded(newCharacter) |
057 | character = newCharacter |
059 | humanoid = newCharacter:WaitForChild( "Humanoid" ) |
061 | hasDoubleJumped = false |
063 | canDoubleJump = false |
065 | oldPower = humanoid.JumpPower |
069 | humanoid.StateChanged:connect( function (old, new) |
071 | if new = = Enum.HumanoidStateType.Landed then |
073 | canDoubleJump = false |
075 | hasDoubleJumped = false |
077 | humanoid.JumpPower = oldPower |
079 | elseif new = = Enum.HumanoidStateType.Freefall then |
081 | wait(TIME_BETWEEN_JUMPS) |
093 | if localPlayer.Character then |
095 | characterAdded(localPlayer.Character) |
101 | localPlayer.CharacterAdded:connect(characterAdded) |
103 | UserInputService.JumpRequest:connect(onJumpRequest) |