If i buy the gamepass i get the item but if i die the item just deletes out of my backpack
code here:
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local gamepassID = 1652088332
local ToolName = "FlyingCarpet"
local carpetTemplate = script:WaitForChild(ToolName)
local function awardTool(player)
if not player.Backpack:FindFirstChild(ToolName) then
local carpetClone = carpetTemplate:Clone()
carpetClone.Parent = player.Backpack
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local success, ownsGamepass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UseId, gamepassID)
end)
if success and ownsGamepass then
awardTool(player)
end
end)
end)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchaseGamepassId, wasPurchased)
if purchaseGamepassId == gamepassID and wasPurchased then
awardTool(player)
end
end)