I’m trying to make a script where when a player bought a developers product it will fireclient a remote event but It’s not working.
the OnClientEvent in local script is not firing and not print the “Done!”, I don’t know why.
Script inside local Script
local event = script:WaitForChild("RemoteEvent")
local MPS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local dp = 000000
local btn = script.Parent
btn.MouseButton1Click:Connect(function()
MPS:PromptProductPurchase(player,dp)
end)
event.OnClientEvent:Connect(function()
print("Done!")
end)
Script inside ServerScript
local MPS = game:GetService("MarketplaceService")
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local dp = 000000
local event = script.Parent
local function processReceipt(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
event:FireClient(player)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MPS.ProcessReceipt = processReceipt
only one at a time in one script at a time
local scripts dont run where scripts run. put the localscript in starterplayerscripts
and the script in serverscriptservice and the remoteEvent in ReplicatedStorage | Roblox Creator Documentation
Put a local script and a click detector under the button and then paste this into the local script:
local plr = game.Players.Localplayer
local Id = -- Product ID Here
local MarketPlaceService = game:GetService("MarketplaceService")
script.Parent.MouseButton1Click:Connect(function()
MarketPlaceService:PromptProductPurchase(plr, <Product ID Here>)
wait(1)
print ("Done!")
end)
Move the RemoteEvent instance to the ReplicatedStorage folder so that both scripts can access it without fail.
local repStorage = game:GetService("ReplicatedStorage")
local event = repStorage:WaitForChild("RemoteEvent")
local MPS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local dp = 000000
local btn = script.Parent
btn.MouseButton1Click:Connect(function()
MPS:PromptProductPurchase(player,dp)
end)
event.OnClientEvent:Connect(function()
print("Done!")
end)
local repStorage = game:GetService("ReplicatedStorage")
local event = repStorage:WaitForChild("RemoteEvent")
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local dp = 000000
local function processReceipt(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
event:FireClient(player)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MPS.ProcessReceipt = processReceipt