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.
COMMUNITY QUESTION
How Would I Make It So When Someone Buys A Gampass They Get A Item In-Game?
1 answer
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.
1 comment
0
This answer is not constructive.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
If you tried something, post your script.