Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to make a shop textbutton a whole Gamepass ?

so basically i made a shop gui that has things like spaws gears and other random things. So i tried so hard to make that shop a gamepass. Like example when i click on the shop i need it to be a gamepass. I tried but i couldnt do that. Can someone help me ?

1 answer

✓ Accepted answer

This is not a request site, so please include a script in which you have tried before, so that we may look at it and correct it. That would help you achieve your goal, help you understand what you did, and be more understandable for anyone viewing this later. Anyways, I'll explain how you would go about this. Firstly, you need to know about PromptPurchase. This is a built in function for local scripts, that will give the player the prompt. So, if you wanted your shop to simply ask them to purchase the gamepass, it would look like this:

-- local script inside the button
local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
	game.MarketplaceService:PromptPurchase(Player, 773709832) -- change the number to the ID of the gamepass, found in its link
end)

Now, this poses one issue. After they purchase it, if they click it, it will still prompt them it! So that means we must use PlayerOwnsAsset. This is another built in function that can check if the player has the asset. So the local script would need to include the following:

local allow = false
if game.MarketplaceService:PlayerOwnsAsset(Player,773709832) then -- checks if he has it, again, replace the id
	allow = true -- sets a variable to true
end

This local script will run every time the character spawns. Now, we must connect the codes.

-- local script inside the button
local allow = false
local Player = game.Players.LocalPlayer
if game.MarketplaceService:PlayerOwnsAsset(Player,773709832) then -- checks if he has it, again, replace the id
	allow = true -- sets a variable to true
end
script.Parent.MouseButton1Down:Connect(function()
	if allow then-- if they have it, do which ever you want
		--execute code. Give them weapons or open admin commands, whatever you want.
	else -- if they do not have it, ask them to purchase
		game.MarketplaceService:PromptPurchase(Player, 773709832) -- change the number to the ID of the gamepass, found in its link
	end
end)

Simply put what you wish to happen when they click it after they purchased the pass, in the block that says 'execute code', and change the IDs. I hope I helped :)

4 comments

0

please accept the answer if I helped

0

but the shop doesnt pop up after buying the gamepass

0

In the part where I said execute code, make the shop visible. Would look something like: script.Parent.Parent.Shop.Visible = true

0

still not workin

This discussion is preserved as it was. New answers, comments, and votes are closed.