Why does my developer product message system does not work?

I am trying to make a system where when a player buys a developer product, a message appears saying “(player who bought the dev product) has bought a developer product!”

But with the current scripts I am using, I keep getting the error

invalid argument #3 (string expected, got nil)

I tried to find a tutorial on how to make something like this but I could not find one.

Here is the script that detects when a player bought a developer product:

local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)        
    if receiptInfo.ProductId == 1073754052 then 
        local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
        game.ReplicatedStorage.ProductBought:FireAllClients()
        if not player then
            return Enum.ProductPurchaseDecision.NotProcessedYet
        end
    end
end

Here is a local script that is supposed to send the message:

game.ReplicatedStorage.ProductBought.OnClientEvent:Connect(function(player)
    script.Parent.Text = player
    script.Parent:TweenPosition(UDim2.new(0.05, 0, 0, 0, "Out", "Sine", 1))
    wait(5)
    script.Parent:TweenPosition(UDim2.new(0.05, 0, -1, 0, "Out", "Sine", 1))
end)

If anyone knows how to fix this, please let me know. Anyway, thank you for your time!

1 Like

First, make sure you are returning Enum.ProductPurchaseDecision.PurchaseGranted for successful purchases.

Secondly, you’re using Tween arguments that have improper open and closing parentheses (you’re trying to write a UDim2 with strings), quick fix:

game.ReplicatedStorage.ProductBought.OnClientEvent:Connect(function(player)
    script.Parent.Text = player
    script.Parent:TweenPosition(UDim2.new(0.05, 0, 0, 0), "Out", "Sine", 1)
    wait(5)
    script.Parent:TweenPosition(UDim2.new(0.05, 0, -1, 0), "Out", "Sine", 1)
end)
1 Like

Thank you for the help! However, your solution unfortunately does not work for me. Once again, thank you for your help.

1 Like