Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Would I Make It So When Someone Buys A Gampass They Get A Item In-Game? [closed]

Asked by 6 years ago

Is there a way to make it so then someone buys a gamepass and it gives them a item in-game i try all of them but they never work.

0
If you tried something, post your script. User#19524 175 — 6y

Closed as Too Broad by User#19524

This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 6 years ago

Put this script's code in a script in StarterPack.

wait(5)

local GamePassService = game:GetService("GamePassService")
local MarketplaceService = game:GetService("MarketplaceService")

local ServerStorage = game.ServerStorage
local GamePassTools = ServerStorage.GamePassTools
local ItemList = {}

local player = script.Parent.Parent

-- Give the tool to this player.
function GiveTool(toolItem)
    local backpackToolItem = toolItem:Clone()
    backpackToolItem.Parent = player.Backpack

    local starterGearToolItem = toolItem:Clone()
    starterGearToolItem.Parent = player.StarterGear
end

-- Checks if the player has the game pass, and if so then give the tool to the player.
-- Otherwise, give the tool to the player after the player gets the game pass.
function CheckForGamePassForTool(toolItem)
    local RequiredGamePassID = toolItem:FindFirstChild("RequiredGamePassID").Value
    local AlreadyHasGamePass = false --player.Name == "MatthewCenance"

    local success, message = pcall(function()
        AlreadyHasGamePass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, RequiredGamePassID)
    end)

    if not success then
        warn("Error: " .. message)
    end

    if AlreadyHasGamePass then
        GiveTool(toolItem)
    else
        MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player2, gamePassID, purchased)
            if player2 == player and gamePassID == RequiredGamePassID then
                if purchased then
                    AlreadyHasGamePass = true
                    GiveTool(toolItem)
                end
            end
        end)
    end
end

for key, toolItem in ipairs(GamePassTools:GetChildren()) do
    spawn(function()
        CheckForGamePassForTool(toolItem)
    end)
end

Then, create a folder titled "GamePassTools" in ServerStorage.

Finally put items in the new folder and for each item in the GamePassTools folder, put in an IntValue named "RequiredGamePassID" with the value of the Game Pass id set as the value of the object.

0
This answer is not constructive. User#19524 175 — 6y
Ad