Hi, I made this script for a part that when touched, prompts a ''Magic Carpet'' gamepass if not owned, if the gamepass is owned then the item is given automatically when the player joins the game, my issue is, it works inside Roblox Studo but not the actual game
script used to give item in game if owned
''local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local InsertService = game:GetService("InsertService")
local GAMEPASS_ID = 1384533590
local ASSET_ID = 225921000 -- Replace with your item asset ID
Players.PlayerAdded:Connect(function(player)
local success, ownsPass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAMEPASS_ID)
end)
if success and ownsPass then
local asset = InsertService:LoadAsset(ASSET_ID)
local tool = asset:FindFirstChildOfClass("Tool")
if tool then
tool.Parent = player:WaitForChild("Backpack")
end
end
end)''
script used to prompt the gamepass if gamepass isn't owned
''local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local GAMEPASS_ID = 1384533590
script.Parent.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
MarketplaceService:PromptGamePassPurchase(player, GAMEPASS_ID)
end
end)
''
