how to make it that when i buy a gamepass i get the item in my inventory
1 Like
To check if player have gamepass:
local user_have_gamepass = game:GetService('MarketplaceService'):UserOwnsGamePassAsync(Player.UserId, Gamepass_ID) -- Cheking if player have item.
if user_have_gamepass then
-- Give item
end
-- ^ This part of code can be used for client-side or server-side scripts. ^
-- Event that fired only when player prompted purchase:
game:GetService('MarketplaceService').PromptGamePassPurchaseFinished:Connect(function(Player, Gamepass_ID, Was_Purchased)
if Player and Gamepass_ID == *Id of gamepass* and Was_Purchased then
-- Give item to player.
end
end)
-- ^ This part of code can be used only for server-side scripts. ^
1 Like
By the way, I know you are new to the Dev forum, but in the future check before posting. There are alot of YouTube videos and other posts that already exist explaining how to do this
Thanks
1 Like
From Prompt GamePass purchase doesn't work - #29 by T3_MasterGamer
Check if player has the game pass using MarketplaceService:UserOwnsGamePassAsync()
and detecting when the player bought the game pass in-game using MarketplaceService.PromptGamePassPurchaseFinished
.
Then, give the player the rainbow carpet using InsertService:LoadAsset()
and gear id of rainbow carpet which is 225921000
.
-- place this script in ServierScriptService, must be a normal script
local Players = game:GetService("Players")
local Debris = game:GetService("Debris") -- used for deleting instances
local MarketplaceService = game:GetService("MarketplaceService")
local InsertService = game:GetService("InsertService")
local gamePassId = 255612370 -- rainbow carpet game pass
local gearId = 225921000 -- rainbow carpet gear
local function rewardPlayer(player: Player)
local gearModel = InsertService:LoadAsset(gearId)
local gear = gearModel:FindFirstChildWhichIsA("BackpackItem") -- gets the tool or hopperbin in gearModel
gear:Clone().Parent = player:WaitForChild("Backpack")
gear.Parent = player:WaitForChild("StarterGear")
Debris:AddItem(gearModel, task.wait()) -- deletes gearModel
end
local function playerJoined(player: Player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId) then
rewardPlayer(player)
end
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, id, success)
if id == gamePassId and success == true then
rewardPlayer(player)
end
end)
for _, player in ipairs(Players:GetPlayers()) do
task.spawn(playerJoined, player)
end
Players.PlayerAdded:Connect(playerJoined)
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.