Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How i can Transfer (in ReplicatedStorage)/Remove a Part after a Purchase?

--  Thanks to @sleazel for this script
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local promptedPlayers = {} --remember players who have been prompted
local productId = 662920300


function Shop(hit)
    if hit.Parent:FindFirstChild("HumanoidRootPart") then --only prompt players
        player = Players:GetPlayerFromCharacter(hit.Parent)
        if not promptedPlayers[player] then
            promptedPlayers[player] = true
            MarketplaceService:PromptProductPurchase(player, productId)
        end
    end
end
script.Parent.Touched:connect(Shop)

I would Remove or Transfer this Part (after the purchase) How i can do it?

3 comments

0

Do you want the part removed only after successful purchase, or regardless of player deciding to buy?

0

After successful purchase!

0

You dont really need to remove it you can just make it transparent and turn of can collide.

1 answer

✓ Accepted answer

EDIT 2 : It is not my best day (see adjustments below). That should solve part not being responsive after declining a purchase. As for part not being destroyed, try script.Parent.Parent:Destroy() instead. It may be that the Parent of the script, is not the plate itself.

EDIT: Sorry I forgot to delete one line!

I did not fully understood Your intentions yesterday. To make a part disappear after a successful purchase, You need to do it inside Your ProcessReceipt function. You should have this function already implemented, make it so there. If not, and ONLY if not, please follow my instructions. DO NOT make multiple ProcessReceipt functions.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productId = 662920300

justOnce = true --set a debounce
function Shop(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then --only prompt players
		local player = Players:GetPlayerFromCharacter(hit.Parent) --EDIT: change to local
		if justOnce then
			justOnce = false
			--promptedPlayers[player] = true EDIT: remove this line, I forgot
			MarketplaceService:PromptProductPurchase(player, productId)
			wait(1)
			justOnce = false
        	end
	end
end
script.Parent.Touched:connect(Shop)

--process player purchase in seperate function
ServerStorage = game:GetService("ServerStorage") --best place to keep unused items

local function processReceipt(receiptInfo)
	
	-- this time find the player, by UserId of whoever made the purchase
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		-- The player probably left the game
		-- If they come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	--IMPORTANT
	if receiptInfo.ProductId == productId then
		--insert code here that will give player whatever they just bought
		print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)

		--Instead of destroying the part, we move it to ServerStorage	
		--script.Parent.Parent = ServerStorage
		--you can destroy it to if you want to, use
		script.Parent:Destroy() --EDIT 2: move this lines here
	end


	return Enum.ProductPurchaseDecision.PurchaseGranted
end
 MarketplaceService.ProcessReceipt = processReceipt

If you process the receipt elsewhere, please ignore this answer. If that is the case, you will need a different approach. Either finding the part in that other script or firing a BindableEvent. Have a nice scripting session.

5 comments

0

Not work >.< i would create a button with the "Tycoon effect"... , but with Robux . If people buy the button, this disappear,but, if people ignore the purchase, the button continues to remain there. I don't know if your script is correct, i can't test it in game, it have 2 problems: Line[8] -> "W003:Global 'player' is only used in the enclosing function" and in line [11] -> promptedPlayers

0

Script edited, should be fine now. IMHO for a one time purchase you should really use a gamepass instead

0

I need use Developer Products, i can't use a GamePass in my situation >.< Nothing has change :( The "window" with "Buy" and "Decline" the purchase, appear only the first time when people touch the part) if they click "Decline", they can't reopen the shop again.. same if people press "Buy", the part continues to remain in the world...

0

Replies in new Post

This discussion is preserved as it was. New answers, comments, and votes are closed.