#gamepass script not working

1 messages · Page 1 of 1 (latest)

round gyro
#

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MarketplaceService = game:GetService("MarketplaceService")

local BuyItemEvent = ReplicatedStorage.Events:WaitForChild("BuyItems")
local Tools = ServerStorage:WaitForChild("Tools")

local Players = game:GetService("Players")

local prices = {["Speed Coil"] = 1500000}

local gamePasses = {["Invisibility Cloak"] = 1405857530} -- id

local function GiveTool(player, ItemName)
local Item = Tools:FindFirstChild(ItemName)
if not Item then print("item not found") return end
if player.Backpack:FindFirstChild(Item.Name) or (player.Character and player.Character:FindFirstChild(Item.Name)) then
return
end
Item:Clone().Parent = player.Backpack
end

BuyItemEvent.OnServerEvent:Connect(function(player, itemName)
print(player.Name, itemName, gamePasses[itemName])
if gamePasses[itemName] then
local success, owns = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePasses[itemName])
end)

    if success and owns then
        print(player.Name .. " owns GamePass for " .. itemName .. ", granting item.")
        GiveTool(player, itemName)
    else
        warn("Purchase failed or player doesn't own GamePass:", itemName)
    end
    return
end


local price = prices[itemName] 
if not price then return end
local leaderstats = player:FindFirstChild("leaderstats")
local Money = leaderstats:WaitForChild("Money")
local Item = Tools:FindFirstChild(itemName)
#

if Money.Value >= price then
print(player.Name .. " bought a " .. itemName)
if Item then
Money.Value = Money.Value - price
local ItemClone = Item:Clone()
ItemClone.Parent = player.Backpack
else
print("Item not found")
end
else
print(player.Name .. " not enough money to buy " .. itemName)
end
end)

Players.PlayerAdded:Connect(function(player)
for name, id in pairs(gamePasses) do
local success, owns = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, id)
end)
if success and owns then
GiveTool(player, name)
end
end
end)

#

the problem is in the server script

#

18:30:46.605 Invisibility Cloak - Client - StoreGUI:47
18:30:46.636 ake9205 Invisibility Cloak 1405857530 - Server - StoreScript:26
18:30:46.636 Purchase failed or player doesn't own GamePass: Invisibility Cloak - Server - StoreScript:36

#

this is the error that itts giving me when i bought it, teh gamepass id is correct running under the game

plain axle
#
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePasses = {
    ["Invisibility Cloak"] = 1405857530, -- check id !
}

local function GiveTool(player, itemName)
    -- add tool logic
    print(player.Name .. " received " .. itemName)
end

local function checkGamePassOwnership(player, gamePassName)
    local gamePassId = gamePasses[gamePassName]
    if not gamePassId then return false end
    
    local success, owns = pcall(function()
        return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId)
    end)
    
    if success then
        return owns
    else
        warn("Failed to check gamepass ownership for "..player.Name..": "..tostring(owns))
        return false
    end
end

-- purchase handeling
local function handlePurchase(player, itemName, price, Item)
    if checkGamePassOwnership(player, itemName) then
        print(player.Name .. " bought a " .. itemName)
        if Item then
            local ItemClone = Item:Clone()
            ItemClone.Parent = player.Backpack
        else
            print("Item not found")
        end
    else
        print("Purchase failed or player doesn't own GamePass: " .. itemName)
    end
end

-- check ownership
Players.PlayerAdded:Connect(function(player)
    wait(2)
    for name, id in pairs(gamePasses) do
        if checkGamePassOwnership(player, name) then
            GiveTool(player, name)
        end
    end
end)

-- Connect  to your RemoteEvent that handles purchases```
meager coyote
plain axle
#

just from what he sent, he will understand the logic of mine, its obivious.

meager coyote
plain axle
mystic pecanBOT
#

studio** You are now Level 1! **studio

plain axle
meager coyote