Basically, this event fires from a server script when a player purchases a product. In my client script, I check if it's the right player by doing if game.Players.LocalPlayer.Name = plr.Name then... It says that the plr value is nil even tho I'm getting it from the OnClientEvent function.
01 | -- Server Script |
02 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
03 | local event = game.ReplicatedStorage [ "Music System" ] .PurchaseMusic |
04 | local function processReceipt(receiptInfo) |
05 | local player = game:GetService( "Players" ):GetPlayerByUserId(receiptInfo.PlayerId) |
06 | if not player then |
07 | return Enum.ProductPurchaseDecision.NotProcessedYet |
08 | end |
09 | if receiptInfo.ProductId = = 655383631 then |
10 | event:FireClient(player) |
11 | end |
12 | return Enum.ProductPurchaseDecision.PurchaseGranted |
13 | end |
14 |
15 | MarketplaceService.ProcessReceipt = processReceipt |
And my client script:
01 | -- Client Script/Local Script |
02 | local event = game.ReplicatedStorage [ "Music System" ] .RequestMusic |
03 | local event 2 = game.ReplicatedStorage [ "Music System" ] .PurchaseMusic |
04 |
05 | event 2. OnClientEvent:Connect( function (plr) |
06 | if game.Players.LocalPlayer.Name = = plr.Name then |
07 | local id = script.Parent.Parent.ChosenID.Value |
08 | event:FireServer(id) |
09 | script.Parent.Text = "Added To Queue" |
10 | end |
11 | end ) |
You have to fire from the server with an additional argument that includes the player. The first argument (the player) tells the game where to send the fire event to (the specified player) so technically it's not an argument when its received from the client's side.
Also, you can't send instances via remotes so you're gonna have to send the name instead.
(btw i removed the player because you don't need to check it, if its sent to the client it was on purpose by the server, it should work nevertheless)
Server
01 | -- Server Script |
02 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
03 | local event = game.ReplicatedStorage [ "Music System" ] .PurchaseMusic |
04 | local function processReceipt(receiptInfo) |
05 | local player = game:GetService( "Players" ):GetPlayerByUserId(receiptInfo.PlayerId) |
06 | if not player then |
07 | return Enum.ProductPurchaseDecision.NotProcessedYet |
08 | end |
09 | if receiptInfo.ProductId = = 655383631 then |
10 | event:FireClient(player) |
11 | end |
12 | return Enum.ProductPurchaseDecision.PurchaseGranted |
13 | end |
14 |
15 | MarketplaceService.ProcessReceipt = processReceipt |
Client
1 | -- Client Script/Local Script |
2 | local event = game.ReplicatedStorage [ "Music System" ] .RequestMusic |
3 | local event 2 = game.ReplicatedStorage [ "Music System" ] .PurchaseMusic |
4 |
5 | event 2. OnClientEvent:Connect( function (plr) |
6 | local id = script.Parent.Parent.ChosenID.Value |
7 | event:FireServer(id) |
8 | script.Parent.Text = "Added To Queue" |
9 | end ) |