I am making a gun gamepass script but it has this weird property that if you test purchase the game pass in studio it works but if you buy it in the actual game it doesn’t work. I’m not sure why this is and I can’t find anything wrong with my script
When Someone Buys The Gamepass Script
local MarketplaceService = game:GetService("MarketplaceService")
local Replicated = game:GetService("ReplicatedStorage")
local WeaponsFolder = Replicated:WaitForChild("Weapons")
local function GiveAllWeapons(player)
for _, v in pairs(WeaponsFolder:GetChildren()) do
if v.Name ~= "OwnerRifle" then
local WeaponClone = v:Clone()
WeaponClone.Parent = player.Backpack
end
end
end
local Weapons = {
AR = 15199188,
Shotgun = 15199196,
SMG = 15199284,
Pistol = 15199361,
GrenadeLauncher = 15199367,
RocketLauncher = 15199383
} -- Change this to your game pass ID
-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true then
for v, i in pairs(Weapons) do
if purchasedPassID == 15199160 then
GiveAllWeapons(player)
return
end
if purchasedPassID == i then
local WeaponClone = WeaponsFolder:WaitForChild(v)
WeaponClone.Parent = player.Backpack
end
end
end
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
When someone with the gamepass joins the game script
local MarketplaceService = game:GetService("MarketplaceService")
local Replicated = game:GetService("ReplicatedStorage")
local WeaponsFolder = Replicated:WaitForChild("Weapons")
local Weapons = {
AR = 15199188,
Shotgun = 15199196,
SMG = 15199284,
Pistol = 15199361,
GrenadeLauncher = 15199367,
RocketLauncher = 15199383
}
local function GiveAllWeapons(player)
for _, v in pairs(WeaponsFolder:GetChildren()) do
if v.Name ~= "OwnerRifle" then
local WeaponClone = v:Clone()
WeaponClone.Parent = player.Backpack
end
end
end
local function TestForGamepass(player, id)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, id)
end)
-- The script below is for checking whether or not the player has the gamepass.
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
for i, v in pairs(Weapons) do
if v == 15199160 then
GiveAllWeapons(player)
return
end
if v == id then
local WeaponClone = WeaponsFolder:WaitForChild(i)
WeaponClone.Parent = player.Backpack
end
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
TestForGamepass(Player, 15199188) -- Rifle
TestForGamepass(Player, 15199196) -- Shotgun
TestForGamepass(Player, 15199284) -- SMG
TestForGamepass(Player, 15199361) -- Pistol
TestForGamepass(Player, 15199367) -- GrenadeLauncher
TestForGamepass(Player, 15199383) -- RocketLauncher
end)
These Scripts don’t raise any errors at all.
Thank you so much if you could spot any flaws at all 