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

How would i make this script work only if i own a certain gamepass?

local Pants = script.Pants
local Shirt = script.Shirt



script.Parent.ClickDetector.MouseClick:connect(function(Player)

    local Character = Player.Character
    if Character == nil then return end

    -- Get new pants
    local CharacterPants = Character:findFirstChild("Pants")
    if CharacterPants then CharacterPants:Destroy() end
    Pants:Clone().Parent = Character

    -- Get new pants
    local CharacterShirt = Character:findFirstChild("Shirt")
    if CharacterShirt then CharacterShirt:Destroy() end
    Shirt:Clone().Parent = Character
end)

How would i make this script work only if i own a certain game pass?

2 answers

https://developer.roblox.com/en-us/articles/Game-Passes-One-Time-Purchases This article will tell you how to use GamePasses in your game for monetization, make sure to thoroughly read it.

For things like items you can purchase over and over go here, https://developer.roblox.com/articles/Developer-Products-In-Game-Purchases again make sure to thoroughly read it.

3 comments

0

Doesn't help...

0

Yes it does..

0

Anyways this might not help him, he will be need MarketPlaceServer instead. Since he already has the gamepass (I assume).)

For this, you will be needing MarketPlaceService:UserOwnsGamePassAsync(). You can learn more about it here

local Pants = script.Pants
local Shirt = script.Shirt

local MarketPlaceService = game:GetService("MarketplaceService")

script.Parent.ClickDetector.MouseClick:connect(function(Player)

	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 0) and Player.Character ~= nil then -- Change "0" to the gamepass id
	    local Character = Player.Character
	
	    -- Get new pants
	    local CharacterPants = Character:findFirstChild("Pants")
	    if CharacterPants then CharacterPants:Destroy() end
	    Pants:Clone().Parent = Character
	
	    -- Get new pants
	    local CharacterShirt = Character:findFirstChild("Shirt")
	    if CharacterShirt then CharacterShirt:Destroy() end
	    Shirt:Clone().Parent = Character
	end
end)

If this helped, remember to accept else report the error and I will fix it asap!

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