Speed coil won't go into players starterpack when bought from developer product

I am trying to make it so when the player touches the part, it prompts the developer product they can buy, and then a speed coil will go into the players starterpack. The prompt worked but the speed coil did not go into the players starterpack.

Code in server script service:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local speedCoil = game:GetService("ServerStorage").SpeedCoil
local Players = game:GetService("Players")

local boughtTimes = 0

local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")

local productFunctions = {}

productFunctions[1780413266] = function(receipt, player)
	local starterPack = game:GetService("StarterPack")
	if starterPack then
		local clonedSpeedCoil = speedCoil:Clone()
		clonedSpeedCoil.Parent = starterPack 
		return true
	end
end

Script under the part

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local touchPart = script.Parent
local productId = 1780413266



touchPart.Touched:Connect(function(otherPart)
	local player = Players:GetPlayerFromCharacter(otherPart.Parent)
	if player then
		MarketplaceService:PromptProductPurchase(player, productId)
	end
end)

Here is the code to add to the players inventory

local GamePassService = game:GetService("GamePassService")

local GamePassID = "Example_GamePassID"
local Player = game.Players:GetPlayerFromCharacter(Player.Character)

if GamePassService:IsPurchased(GamePassID) then

Player:Inventory:AddItem(GearID)

end)
1 Like

But I am trying to do this through developer product purchase

Try using Avatar editor service. You can check if a user owns an asset.

The issue you’re having is that you’re trying to add the item to the StarterPack. That’s a service that allows players to receive items upon spawning. You need to directly add the item to the player’s inventory. Replace the code that sets the parent of the coil to the starterPack and instead make it the player’s inventory.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.