2016-08-21 6 views
0

一切都在問題中。當你點擊一個零件時,gui打開並且你有一個按鈕。當你點擊它時,一個開發者產品賣家出現,你需要購買它。如果你不這樣做,沒有任何反應。但是如果你購買它,你可以從ServerStorage獲得一個克隆的工具。 (該工具是一臺iPad)單擊一個部件打開一個gui,然後通過單擊一個TXTButton銷售一個開發人員產品。 [ROBLOX]

這裏是開發產品ID:37693110

回答

0

the tutorial獲得的圖形用戶界面是如何工作的幾點認識。

要收聽點擊零件,請使用ClickDetectors

您可以prompt a purchasedeveloper product,然後確認玩家用ProcessReceipt購買了它。

爲了使點擊檢測工作,把下面的腳本中的一部分:

local Block = script.Parent 

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

要顯示一個播放器的圖形用戶界面,你可以使用:

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

哪裏game.ServerStorage.PurchaseGUI是你的GUI和PlayerPlayer。如果一個GUI位於PlayerGUI中,它將被繪製。除非你告訴它not to

listen on a clickTextButton,你可以使用:

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

要提示購買,你可以使用下面的代碼:

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

Player是球員和ProductId是你的產品編號(37693110是您產品的編號)

要收聽購買,您可以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授予的球員。如果你想讓它持續重生,你可能還想考慮將它添加到StarterPack

您可能還想要購買save the information,以便玩家在重新加入遊戲時獲得該工具。

如果你把它放在一起:

服務器scriptServerScriptService

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) 
相關問題