I need help with DevProducts

So I have a devprducts script where I have already two devproducts that work but when I test the third one it works the same as the second one (I buy Skip stage and it Kills all). here is the script, hope someone can help!

Blockquote
local event = game.ReplicatedStorage:WaitForChild(“Deaddd”)
local mps = game:GetService(“MarketplaceService”)
local event1 = game.ReplicatedStorage:WaitForChild(“Skipp”)

Blockquote
mps.ProcessReceipt = function(receiptinfo)
if receiptinfo.ProductId == 2837290715 then
local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
event:FireAllClients()
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptinfo.ProductId == 2837282187 then
for i,v in pairs(game.Players:GetPlayers()) do
if (v.UserId ~= receiptinfo.PlayerId and v.Character and v.Character:FindFirstChild(“Humanoid”)) then
v.Character:FindFirstChild(“Humanoid”).Health = 0
print(“killed all”)
elseif receiptinfo.ProductId == 2838745402 then
print(“purchased skip stage”)
event1:FireClient()
end
end
end
end

Your issue comes from a misplaced elseif statement inside the for loop, heres a fixed version of your code.

local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local eventKill = game.ReplicatedStorage:WaitForChild("Deaddd")
local eventSkip = game.ReplicatedStorage:WaitForChild("Skipp")


mps.ProcessReceipt = function(receiptInfo)
    local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then return Enum.ProductPurchaseDecision.NotProcessed end

    if receiptInfo.ProductId == 2837290715 then
        for _, v in pairs(players:GetPlayers()) do
            if v.UserId ~= receiptInfo.PlayerId and v.Character and v.Character:FindFirstChild("Humanoid") then
                v.Character.Humanoid.Health = 0
            end
        end
        print("Killed all players")
        return Enum.ProductPurchaseDecision.PurchaseGranted
    elseif receiptInfo.ProductId == 2837282187 then
        eventKill:FireAllClients()
        return Enum.ProductPurchaseDecision.PurchaseGranted
    elseif receiptInfo.ProductId == 2838745402 then
        print("Purchased skip stage")
        eventSkip:FireClient(player)
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end

    return Enum.ProductPurchaseDecision.NotProcessed
end

thanks so much! this worked perfectly!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.