单击一个部分打开一个图形用户界面,然后通过单击一个 TXTButton 来销售开发者产品。 [罗布乐思]

Click on a part to open a gui then sell a developer product by clicking on a TXTButton. [ROBLOX]

一切都在问题中。当你点击一个部分时,图形用户界面打开,你有一个按钮。当你点击它时,会出现一个开发者产品卖家,你需要购买它。如果你不这样做,什么也不会发生。但是如果你购买它,你会得到一个从 ServerStorage 克隆的工具。 (工具是iPad)

这里是开发者产品ID:37693110

阅读 the tutorial 以了解 GUI 的工作原理。

要监听某个部分的点击次数,您可以使用 ClickDetectors

你可以prompt a purchase of a developer product, and then confirm that a Player have bought it with ProcessReceipt.

要使点击检测起作用,请将以下脚本放在一个部分中:

local Block = script.Parent

local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = Block
ClickDetector.MouseClick:connect(function(Player)
    -- Stuff
end)

要向玩家显示 GUI,您可以使用:

local GUI = game.ServerStorage.PurchaseGUI
GUI:Clone().Parent = Player.PlayerGUI

其中 game.ServerStorage.PurchaseGUI 是您的 GUI,PlayerPlayer. If a GUI is in the PlayerGUI, it is drawn. Unless you tell it not to

listen on a click on a TextButton,可以使用:

local Button = <Button Here>
Button.MouseButton1Click:connect(function()
    -- Stuff here
end)

要提示购买,您可以使用以下代码:

local ProductId = 37693110
Game:GetService("MarketplaceService"):PromptProductPurchase(Player, ProductId)

其中 Player 是播放器,ProductId 是您的产品 ID(37693110 是您的产品 ID)

要听购买,您可以use:

local MarketplaceService = game:GetService("MarketplaceService")
local ProductId = 37693110

function MarketplaceService.ProcessReceipt(ReceiptInfo)
    local Player = game:GetService("Players"):GetPlayerByUserId(ReceiptInfo.PlayerId)
    if not player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if receiptInfo.ProductId == ProductId then
        -- Do stuff
        return Enum.ProductPurchaseDecision.PurchaseGranted
    else
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end
end

并给clone一个工具:

game.ServerStorage.iPad:Clone().Parent = Player.Backpack

如果您希望工具持续重生,则将其放置在 Backpack. You might want to consider also adding it to the StarterPack 中即可授予玩家工具。

您可能还想 save the information 关于购买,以便玩家在重新加入游戏时获得工具。

如果你把它们放在一起:

一台服务器script in ServerScriptService:

local ProductId = 37693110
local MarketplaceService = game:GetService("MarketplaceService")
local Block = script.Parent
local GUI = game.ServerStorage.PurchaseGUI

local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = Block
ClickDetector.MouseClick:connect(function(Player)
    GUI:Clone().Parent = Player.PlayerGUI
end)

function MarketplaceService.ProcessReceipt(ReceiptInfo)
    local Player = game:GetService("Players"):GetPlayerByUserId(ReceiptInfo.PlayerId)
    if not player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if receiptInfo.ProductId == ProductId then
        game.ServerStorage.iPad:Clone().Parent = Player.Backpack
        return Enum.ProductPurchaseDecision.PurchaseGranted
    else
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end
end

在 GUI 中的按钮中有一个 local script

local ProductId = 37693110
local Button = script.Parent
local Player = game.Players.LocalPlayer

Button.MouseButton1Click:connect(function()
    Game:GetService("MarketplaceService"):PromptProductPurchase(Player, ProductId)
end)