#I want to check if the player owns the gamepass, if yes, they get increased jump height and vice ver

1 messages · Page 1 of 1 (latest)

shut lotus
#

heres the code! any help is appreciated!

local GamepassID = 1238328876 -- Change this ID to your gamepass ID
local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- If the part detects a humanoid then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        MarketplaceService:PromptGamePassPurchase(plr,GamepassID)
    end
end)
frail sage
shut lotus
#

it is located within a part called 'BuyBase' within workspace, within a folder called 'BananaCase', it isnt a local script it is a regular script 🙂

frail sage
#

if its a script i would use UserOwnsGamePassAsync

shut lotus
#

where do i put that in the code though?

frail sage
shut lotus
#

yeah how do i do that? 🙂

frail sage
shut lotus
#

YES EXACTLY THAT

frail sage
#

😭

shut lotus
#

like LITERALLY

#

THAT

frail sage
#

alright u want the script and i tell u some changes and whats wrong or u jst want the script and not me yap or u wanna do it urself

shut lotus
#

honestly... the second option

frail sage
#

reasonable

shut lotus
#

sorry im so tired im english its 2am for me i just wanted to do this and sleep

frail sage
#

ye i feel ya lemme get it for u then, i added a debounce to it to prevent spammin as well the boost control gamepass ownership check

shut lotus
#

thank you so much.

frail sage
#
local GamepassID = 1238328876
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local debounce = {}

script.Parent.Touched:Connect(function(hit)
    local character = hit.Parent
    local humanoid = character:FindFirstChild("Humanoid")
    if humanoid then
        local player = Players:GetPlayerFromCharacter(character)
        if player and not debounce[player] then
            debounce[player] = true

            humanoid.JumpHeight = 50

            local success, ownsPass = pcall(function()
                return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)
            end)

            if success and ownsPass == true then
                humanoid.JumpHeight = 100
            else
                MarketplaceService:PromptGamePassPurchase(player, GamepassID)
            end

            task.delay(3, function()
                debounce[player] = nil
            end)
        end
    end
end)

shut lotus
#

legend!!!!!

frail sage
shut lotus
#

wait hold on!!!!

shut lotus
frail sage
#

mm i suppose u dont want that?

shut lotus
#

no thank you please!

frail sage
#

fs fs do u want it to save when u leave then rejoin u keep the jump boost?

shut lotus
#

basically the player just always has a jump boost after buying the pass no matter what :)?

frail sage
#

alr no matter what

shut lotus
#

yes!

frail sage
shut lotus
#

yes! sorry does it also keep the jump height if the player leaves and rejoins i assume? sorry, VERY new.

frail sage
#

Yup it does Thumbs

shut lotus
#

Heck Yeah! tysm!

frail sage
#
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local GamepassID = 1238328876
local debounce = {}
local playerOwnsPass = {}


local function checkOwnership(player)
    local success, ownsPass = pcall(function()
        return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)
    end)
    if success then
        playerOwnsPass[player] = ownsPass
    else
        playerOwnsPass[player] = false
    end
end

local function applyJumpBoost(character, ownsPass)
    local humanoid = character:WaitForChild("Humanoid")
    if ownsPass then
        humanoid.JumpHeight = 100
    else
        humanoid.JumpHeight = 50
    end
end

Players.PlayerAdded:Connect(function(player)
    checkOwnership(player)
    player.CharacterAdded:Connect(function(character)
        applyJumpBoost(character, playerOwnsPass[player])
    end)
end)
Players.PlayerRemoving:Connect(function(player)
    playerOwnsPass[player] = nil
end)

script.Parent.Touched:Connect(function(hit)
    local character = hit.Parent
    local humanoid = character and character:FindFirstChild("Humanoid")
    if not humanoid then return end
    local player = Players:GetPlayerFromCharacter(character)
    if not player then return end
    if debounce[player] then return end
    debounce[player] = true
    checkOwnership(player)
    if not playerOwnsPass[player] then
        MarketplaceService:PromptGamePassPurchase(player, GamepassID)
    end
    task.delay(3, function()
        debounce[player] = nil
    end)
end)

#

there you are

#

lmk if thers issues

shut lotus
#

LEGEND will do tysm!

frail sage
#

ofc yw

shut lotus
# frail sage ofc yw

dont hate me but how do i make a slight change in the script for it to increase walkspeed instead of jump height, i tried replacing jump height with WalkSpeed and changing the pass ID but it doesnt seem to work!

#
 local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local GamepassID = 1238025674
local debounce = {}
local playerOwnsPass = {}


local function checkOwnership(player)
    local success, ownsPass = pcall(function()
        return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)
    end)
    if success then
        playerOwnsPass[player] = ownsPass
    else
        playerOwnsPass[player] = false
    end
end

local function applySpeedBoost(character, ownsPass)
    local humanoid = character:WaitForChild("Humanoid")
    if ownsPass then
        humanoid.WalkSpeed = 32
    else
        humanoid.WalkSpeed = 16
    end
end

Players.PlayerAdded:Connect(function(player)
    checkOwnership(player)
    player.CharacterAdded:Connect(function(character)
        applySpeedBoost(character, playerOwnsPass[player])
    end)
end)
Players.PlayerRemoving:Connect(function(player)
    playerOwnsPass[player] = nil
end)

script.Parent.Touched:Connect(function(hit)
    local character = hit.Parent
    local humanoid = character and character:FindFirstChild("Humanoid")
    if not humanoid then return end
    local player = Players:GetPlayerFromCharacter(character)
    if not player then return end
    if debounce[player] then return end
    debounce[player] = true
    checkOwnership(player)
    if not playerOwnsPass[player] then
        MarketplaceService:PromptGamePassPurchase(player, GamepassID)
    end
    task.delay(3, function()
        debounce[player] = nil
    end)
end)
rigid ember
#

Check if the player is added before checking for ownership

#

Ex: player.CharacterAdded:Connect(function(character)
checkOwnership(player) -- <-- Add this here to re-check ownership
applySpeedBoost(character, playerOwnsPass[player])
end)

#

Also check if there are other scripts that might override this

#

Final fix (copy + paste):

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local GamepassID = 1238025674
local debounce = {}
local playerOwnsPass = {}

local function checkOwnership(player)
local success, ownsPass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)
end)
if success then
playerOwnsPass[player] = ownsPass
else
playerOwnsPass[player] = false
end
end

local function applySpeedBoost(character, ownsPass)
local humanoid = character:WaitForChild("Humanoid")
if ownsPass then
humanoid.WalkSpeed = 32
else
humanoid.WalkSpeed = 16
end
end

Players.PlayerAdded:Connect(function(player)
checkOwnership(player)
player.CharacterAdded:Connect(function(character)
checkOwnership(player) -- <-- Re-check on spawn
applySpeedBoost(character, playerOwnsPass[player])
end)
end)

Players.PlayerRemoving:Connect(function(player)
playerOwnsPass[player] = nil
end)

script.Parent.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character and character:FindFirstChild("Humanoid")
if not humanoid then return end
local player = Players:GetPlayerFromCharacter(character)
if not player then return end
if debounce[player] then return end
debounce[player] = true
checkOwnership(player)
if not playerOwnsPass[player] then
MarketplaceService:PromptGamePassPurchase(player, GamepassID)
end
task.delay(3, function()
debounce[player] = nil
end)
end)