How to make a gamepass button where you would automatically get a tool once you purchase the gamepass

i have this boombox tool that i’m using for the gamepass in my city game, and i’m thinking about making a script where you would automatically get the tool after you purchase the gamepass

there were youtube videos talking about gamepass tool buttons, but the problem was you would have to rejoin to get the gamepass when you’re in the game
the good news is there is one video similar to what i was talking about Roblox | How to make a Gamepass Gear Script | 2019 [FE] - YouTube, but unfortunately the video was 3 years ago, and filteringenabled doesn’t exist anymore

could someone help me with this and tell me what to do to make my button give someone the tool once they purchase the gamepass

hopefully this probably makes sense

btw im not really that much of a scripter person so i might not know stuff like connect(function() or whatever those are

1 Like

PromptGamePassPurchaseFinished. About as simple as that. You’re welcome to implement additional strategies to make sure players get their items upon respawns or similar, such as caching the player’s purchase or placing it into their StarterGear (as simple examples).

You would have to insert the tool into the player’s backpack, here is a sample script I made:

local gamepassId = -- Your gamepass ID here
local marketplaceService = game:GetService("MarketplaceService")
local tool = -- Your tool path

marketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamepId, wasPurchased)
if wasPurchased and gamepId == gamepassId then
local newTool = tool:Clone()
newTool.Parent = player.Backpack
end)

I haven’t tested it but let me know if you are getting any errors.

2 Likes

is “tool path” supposed to be the name of the tool you are using it for

You are supposed to add the path for the tool for example, if you have it in ReplicatedStorage:
game.ReplicatedStorage.Tool

how do i add a tool path in replicatedstorage

clone the tool and then put it in replicated storage

do you mean like putting the tool you have into replicatedstorage

Yeah but it can also go to ServerStorage, make sure to identify it correctly, though.

is there a part in that where the script would give the user a tool

No, the page just includes a code sample of how you can use PromptGamePassPurchaseFinished. It’s up to you to determine how to customise the connected function to give the user a tool.

but what if idk how to do any of that stuff since i mentioned earlier that i’m not a good scripter like some people

The Developer Hub has many articles and reference pages you can scroll through to learn or understand how to accomplish some things. There are some coding tutorials and documentation of API there but then the other half is doing problem solving by applying what you know or have learned in order to create the system you’re looking for.

It, along with the toolbox, have good materials if you’re looking to dive into programming or get a reference for how some things may be accomplished.

i searched on devhub (developer hub) searching what i was talking about and i didn’t find anything that was related to what i wanted

To further help with your issue here is some information regarding your issue which should help:

If your still not able to solve your problem ask some questions and I’ll help you out.

i am still confused since i’m not a scripter but i can ask you this

do you know how to make something like this Roblox | How to make a Gamepass Gear Script | 2019 [FE] - YouTube but a little updated, because that’s what i’m trying to make for my gamepass button to work whenever someone purchases the gamepass and then it gives them the tool if you know what i mean

I can’t provide you all the code but I can lead you in the correct direction.

--Client
local MarketPlaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
MarketPlaceService:PromptGamePassPurchase(Player, 999999) --Player, GamepassId (The one in the URL)

--Server
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Tool = ReplicatedStorage:WaitForChild("SomeTool")

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(Player, Id, Purchased)
	if Id == 999999 then --The gamepass Id
		if Purchased then
			print(Player.Name.. " purchased a tool!")
			local Tool = Tool:Clone() --Create new tool for the player
			Tool.Parent = Player.Backpack
		end
	end
end)

image

Also you should add the tool to the players startergear so that the player doesnt lose it when they die

unfortunately it didn’t work even if i did that stuff i saw on your reply

but i guess i might use this tutorial here about gamepasses that would give you a tool Roblox Scripting Tutorial: How to Script Gamepass Tools - YouTube even if you have to rejoin to get the tool from the gamepass you just bought