I have been trying for a long time to get my gamepass scripts to work to give an item when bought but they aren't working if anyone please knows why they aren't working or has a working one please tell me in the answers. Much appreciated

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local gamePassID = 4919176  

local function onPlayerAdded(player)
 
    local hasPass = false
 
    
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
    end)
 
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end
 
    if hasPass == true then
        print(player.Name .. " owns the game pass with ID " .. gamePassID)
        
   
local item = game:GetService("ReplicatedStorage"):WaitForChild("SpeedCoil")


local db = true

script.Parent.Touched:connect(function(part)
 if part.Parent:FindFirstChild("Humanoid") ~= nil then
  local player = game.Players:GetPlayerFromCharacter(part.Parent)
  if player ~= nil then
   if player.Backpack ~= nil then
    if db == true then
     db = false
     item:Clone().Parent = player.Backpack
     wait(1)
     db = true
    end
   end
  end
 end
end)
    end
end
 
Players.PlayerAdded:Connect(onPlayerAdded)

2 comments

0

Is it outputting an errors or just not giving you the item?

0

not giving me the item