Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Double Jump Gamepass Script is working in studio but not in-game?

Asked by 5 years ago
Edited 5 years ago
local passId = 4916610
local MPS = game:GetService("MarketplaceService")

local function isAuthenticated(userId, gamePassId) -- define outside the PlayerAdded event
    return MPS:UserOwnsGamePassAsync(userId, gamePassId)
end

game:GetService("Players").PlayerAdded:Connect(function(plr) -- :connect is deprecated, use :Connect

    plr.CharacterAdded:Connect(function(char) -- wait for the character! 
        if isAuthenticated(plr.UserId, passId) then
           local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character
local humanoid

local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local time_delay = 0.1
local jump_multiplier = 1.5 -- set to 1 for a normal double jump, increase for the second jump to be higher

function onJumpRequest()
    if not character or not humanoid or not character:IsDescendantOf(workspace) or humanoid:GetState() == Enum.HumanoidStateType.Dead then
        return
    end

    if canDoubleJump and not hasDoubleJumped then
        hasDoubleJumped = true
        humanoid.JumpPower = oldPower * jump_multiplier
        humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    end
end

local function characterAdded(new)
    character = new
    humanoid = new:WaitForChild("Humanoid")
    hasDoubleJumped = false
    canDoubleJump = false
    oldPower = humanoid.JumpPower

    humanoid.StateChanged:connect(function(old, new)
        if new == Enum.HumanoidStateType.Landed then
            canDoubleJump = false
            hasDoubleJumped = false
            humanoid.JumpPower = oldPower
        elseif new == Enum.HumanoidStateType.Freefall then
            wait(time_delay)
            canDoubleJump = true
        end
    end)
end

if player.Character then
    characterAdded(player.Character)    
end

player.CharacterAdded:connect(characterAdded)
UIS.JumpRequest:connect(onJumpRequest)
        end
    end)
end)
0
please clean up the original post, Use the Lua code block button and remove the lines of ~~~ in your code so that it doenst mess up the code blocks Rubenske1 89 — 5y
0
Alright! TimeExotic -6 — 5y
0
Is your game FilteringEnabled? Nurame_Duff 7 — 5y
0
Yeah, but due to roblox's new update I have to keep it FilteringEnabled... TimeExotic -6 — 5y

Answer this question