(HELP) Inventory shop in obby doesn't work

Hi! I was creating a shop where players can buy items shown in their inventory section. Is there a way where I could make it prompt the player to purchase the chosen item, and have them unequip it when they cancel the purchase? Thanks!

Code:

local player = game.Players.LocalPlayer
local mps = game:GetService("MarketplaceService")
local inventory = player.Backpack
local gravityCoil = game:GetService("ReplicatedStorage"):FindFirstChild("GravityCoil"):Clone()
local gcid = 1051183559
local gravityCoilClaim = game:GetService("ReplicatedStorage"):FindFirstChild("GravityCoil")
local speedCoil = game:GetService("ReplicatedStorage"):FindFirstChild("SpeedCoil"):Clone()
local fusionCoil = game:GetService("ReplicatedStorage"):FindFirstChild("FusionCoil"):Clone()
local flyingCarpet = game:GetService("ReplicatedStorage"):FindFirstChild("FlyingCarpet"):Clone()
local grappleHook = game:GetService("ReplicatedStorage"):FindFirstChild("GrappleHook"):Clone()

if inventory:FindFirstChild("GravityCoil") then
	print("Already")
else
	gravityCoil.Parent = inventory
end
inventory.GravityCoil.Equipped:Connect(function()
	mps:PromptGamePassPurchase(player, gcid)
end)

Hello, You can add a local script inside your tool and paste this in!

local MarketplaceService = game:GetService("MarketplaceService")

local Tool = script.Parent

local Player = game.Players.LocalPlayer

local ProductId = 1051183559

Tool.Equipped:Connect(function()

	if not MarketplaceService:UserOwnsGamePassAsync(Player.UserId, ProductId) then
		
		Player.Character:WaitForChild("Humanoid"):UnequipTools()
		MarketplaceService:PromptProductPurchase(Player, ProductId)
		
	end

end)
1 Like

Would the tool go in the starterpack?

Yes! The tool does go in the starterpack section.

image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.