Hi So I am Currently making a Revive System where Player can pay Devproduct to revive himself, or to revive His teammate.
Here is the code on ServerScript for the revive.
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
Players.PlayerAdded:Connect(function(player)
repeat task.wait() until player and (player.Character or player.CharacterAdded:Wait()) and player.Character:FindFirstChild("Humanoid")
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
humanoid.HealthChanged:Connect(function(health)
--Code to make people downed and create proximity
proximityPrompt.Triggered:Connect(function(plr)
MarketplaceService:PromptProductPurchase(plr, 123)
MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, isPurchased)
if productId ~= 123 or not isPurchased then return end
-- code to revive player using the variables of humanoid and playerInstance previously defined here
end)
end)
end)
end)
Here is the ProcessReceipt Script
local MarketplaceService = game:GetService("MarketplaceService")
productFunctions[123] = function(receipt, player)
return true
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the developer product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The user has received their benefits
-- Return "PurchaseGranted" to confirm the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- The user's benefits couldn't be awarded
-- Return "NotProcessedYet" to try again next time the user joins
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Set the callback; this can only be done once by one server-side script
MarketplaceService.ProcessReceipt = processReceipt
The reason I am using .PromptProductPurchaseFinished is because so that It can use the previously defined humanoid & ProximityPrompt variable In the revive script to revive other player or the person that bought the DevProduct.
Is this method efficient or is there better alternative to make this? Thanks