I have a GravityCoilScript inserted in Workspace and I have a Local script inserted in the button that gives you the option to buy the Gamepass. The problem is that when I buy the Gamepass, the item does not appear for the player to use. Can anyone tell me what ive done wrong? I also inserted a GravityCoil inside of ServerStorage
You have to listen for the event via PromptGamePassFinished, it won’t just fire the moment as soon as you purchase the weapon you need to connect it so that it’ll detect when to check:
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ID = 17640517
local function Spawned(Player)
local HasGamepass = false
local success, whoops = pcall(function()
HasGamepass = MPS:UserOwnsGamePassAsync(Player.UserId, ID)
end)
if success and HasGamepass then
local Tool = game.ServerStorage.GravityCoil:Clone()
Tool.Parent = Player.Backpack
local StarterTool = game.ServerStorage.GravityCoil:Clone()
StarterTool.Parent = Player.StarterGear
else
warn("Checking if the Player has a Gamepass, more info: ", whoops)
end
end
MPS.PromptGamePassPurchased:Connect(function(Player, ID, PurchaseCheck)
if PurchaseCheck == true then
local Tool = game.ServerStorage.GravityCoil:Clone()
Tool.Parent = Player.Backpack
local StarterTool = game.ServerStorage.GravityCoil:Clone()
StarterTool.Parent = Player.StarterGear
else
warn("Something unexpectedly happened while detecting the purchase to the player")
end
end)
Players.PlayerAdded:Connect(Spawned)