Hello Devs!
im making a troll system for my game but the ProcessReceipt fails could anyone help me?
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SelectTarget = ReplicatedStorage:WaitForChild("SelectTarget")
local Products = require(ReplicatedStorage:WaitForChild("Presets"):WaitForChild("TrollProducts"))
-- [userId] = {target, action, productId}
local pending = {}
SelectTarget.OnServerEvent:Connect(function(player, targetUserId, action)
if typeof(targetUserId) ~= "number" then return end
if typeof(action) ~= "string" then return end
local productId = Products[action]
if not productId then return end
local target = Players:GetPlayerByUserId(targetUserId)
if not target then return end
pending[player.UserId] = {
target = targetUserId,
action = action,
productId = productId
}
end)
local function ApplyEffect(target, action)
if not target then return end
local character = target.Character
if not character then
character = target.CharacterAdded:Wait()
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
local root = character:FindFirstChild("HumanoidRootPart")
if action == "Kill" then
humanoid.Health = 0
elseif action == "Freeze" then
root.Anchored = true
task.delay(5, function()
if root and root.Parent then
root.Anchored = false
end
end)
elseif action == "Fling" then
local bv = Instance.new("BodyVelocity")
bv.Velocity = Vector3.new(0, 200, 0)
bv.MaxForce = Vector3.new(1e6, 1e6, 1e6)
bv.Parent = root
task.delay(0.5, function()
if bv then bv:Destroy() end
end)
elseif action == "Explode" then
local explosion = Instance.new("Explosion")
explosion.Position = root.Position
explosion.Parent = workspace
elseif action == "Kick" then
if target.AccountAge >= 3 then
target:Kick("You were trolled!")
end
end
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local request = pending[player.UserId]
if request and request.productId == receiptInfo.ProductId then
local target = Players:GetPlayerByUserId(request.target)
if target then
ApplyEffect(target, request.action)
end
pending[player.UserId] = nil
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end