Hi all, I tried to make a gamepass GUI for two classic tools - Speed Coil and Jump Coil. For some reason though when I purchase the gamepass it doesn’t give me the tools. Here are my scripts:
Script in ServerScriptService
local mps = game:GetService("MarketplaceService")
local gamepass_id = 17930931 --enter the gamepass asset id here
local plrs = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
if mps:UserOwnsGamePassAsync(player.UserId , gamepass_id) then
game.ServerStorage.JumpCoil:Clone().Parent = player.Backpack
game.ServerStorage.JumpCoil:Clone().Parent = player.StarterGear
end
end)
Local Script in the Purchase GUI Text Button
local ID = 17930931 -- JumpCoil ID
script.Parent.MouseButton1Click:Connect(function()
game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,ID) -- Prompts the purchase
end)
Yeah, the player will need to rejoin in order to recieve the tools since the mps:UserOwnsGamePassAsync condition check happens only once. I suggest adding an extra player.CharacterAdded event in which you will place that condition so instead of rejoining the player would need to reset to recieve these tools.
local MarketplaceService = game:GetService("MarketplaceService")
local gamePassID = {gamepass id}
-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassID then
--give the tools
end
end
-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
Not sure if I did it right, but unfortunately it doesn’t work yet:
local MarketplaceService = game:GetService("MarketplaceService")
local gamePassID = {17930931}
-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassID then
game.ServerStorage.JumpCoil:Clone().Parent = player.Backpack
game.ServerStorage.JumpCoil:Clone().Parent = player.StarterGear
end
end
-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
local MarketplaceService = game:GetService("MarketplaceService")
local gamePassID = (17930916)
-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassID then
game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear
end
end
-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
local ID = 17930916 -- SpeedCoil ID
script.Parent.MouseButton1Click:Connect(function()
game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,ID) -- Prompts the purchase
end)
Nevermind, that part works - it gives the tool now. The only thing is, when I leave and rejoin I no longer have the tools.
How do I make it so I get the tools on rejoin as well?
local MarketplaceService = game:GetService("MarketplaceService")
local SpeedCoil = 17930916
local GravityCoil = 17930931
game.Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId , GravityCoil) then
game.ServerStorage.JumpCoil:Clone().Parent = player.Backpack
game.ServerStorage.JumpCoil:Clone().Parent = player.StarterGear
end
if MarketplaceService:UserOwnsGamePassAsync(player.UserId , SpeedCoil) then
game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear
end
end)
-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true then
if purchasedPassID == SpeedCoil then
game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear
elseif purchasedPassID == GravityCoil then
game.ServerStorage.GravityCoil:Clone().Parent = player.Backpack
game.ServerStorage.GravityCoil:Clone().Parent = player.StarterGear
end
end
end
-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)