I want to make a buy developer product system. The way it works is simple: Click on button, another gui for confirmation, click ok, show roblox buy developer product in-built prompt, when clicked, server handle transaction and then fire remote event to same client and when client receive it it shows a gui that says buy success. Everything works exactly the way i want them except the client doesn’t receive the remote event. I used print function and the server fires the event ok, but the client doesn’t receive it. I have print function on both client and server. Here is the code:
Summary
for i, v in pairs(buyGemTableName) do
productFunctions[tonumber(v)] = function(receipt, plr)
plr.Gems.Value += tonumber(buyGemTable[v])
print(“BUY GEM”)
game.ReplicatedStorage.BuyGem:FireClient(plr,true,“SUCCESSFULLY BOUGHT “…tostring(buyGemTable[v])…” GEMS!”)
print(“FIRED!”)
end
end
local function processReceipt(receiptInfo)
local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
-- Determine if the product was already granted by checking the data store
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
local success, errorMessage = pcall(function()
purchased = marketData:GetAsync(playerProductKey)
end)
-- If purchase was recorded, the product was already granted
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
print("Data store error:" .. errorMessage)
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
end
-- Find the player who made the purchase in the server
if not plr then
-- The player probably left the game
-- If they come back, the callback will be called again
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
print("ERROR")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Look up handler function from 'productFunctions' table above
local handler = productFunctions[receiptInfo.ProductId]
-- Call the handler function and catch any errors
local success, result = pcall(handler, receiptInfo, plr)
if not success then
warn("Error occurred while processing a product purchase")
warn(result)
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", plr)
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Record transaction in data store so it isn't granted again
local success, errorMessage = pcall(function()
marketData:SetAsync(playerProductKey, true)
end)
if not success then
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
print("Cannot save purchase data: " .. errorMessage)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
The above code works all well and correct. The print function also prints. But the client doesn’t receive it.
Summary
t = confirmBuyGem.Yes.MouseButton1Click:Connect(function()
t:Disconnect()
print(“CLICK BUY”)
local productID = buyGemTable[tostring(gems)]
confirmBuyGem.Yes.Visible = false
confirmBuyGem.No.Visible = false
confirmBuyGem.Message.Visible = false
game:GetService(“MarketplaceService”):PromptProductPurchase(player, productID)
confirmBuyGem.Processing.Visible = true
confirmBuyGem.Processing.BackgroundColor3 = Color3.fromRGB(255, 255, 127)
local buySuccess = false
local message = nil
confirmBuyGem.Ok.Visible = false
game.ReplicatedStorage.BuyGem.OnClientEvent:Connect(function(bool,msg)
print(“ON EVENT”)
buySuccess = bool
message = msg
print(bool)
print(msg)
end)
local waitTime = 0.3
local timeOut = 20
repeat
confirmBuyGem.Processing.Text = "PROCESSING . "
timeOut -= waitTime
wait(waitTime)
confirmBuyGem.Processing.Text = "PROCESSING . . "
timeOut -= waitTime
wait(waitTime)
confirmBuyGem.Processing.Text = "PROCESSING . . . "
timeOut -= waitTime
wait(waitTime)
until buySuccess or timeOut < 0 or message ~= nil
if not buySuccess then
confirmBuyGem.Processing.Text = “PURCHASING FAILED. PLEASE TRY AGAIN LATER.”
confirmBuyGem.Processing.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
else
confirmBuyGem.Processing.Text = “PURCHASING SUCCESSFUL!”
confirmBuyGem.Processing.BackgroundColor3 = Color3.fromRGB(85, 255, 0)
end
if message then
confirmBuyGem.Processing.Text = message
end
confirmBuyGem.Ok.Visible = true
confirmBuyGem.Ok.MouseButton1Click:Connect(function()
confirmBuyGem.Visible = false
end)
wait(0.1)
debounceGem = false
end)
The three print functions in there doesn’t print at all. I’m wondering is it because of the t:Disconnect()? It supposed to only disconnects the MouseButton1Click event. If you read so far, please help me thank you so much.
SERVER
for i, v in pairs(buyGemTableName) do
productFunctions[tonumber(v)] = function(receipt, plr)
plr.Gems.Value += tonumber(buyGemTable[v])
print("BUY GEM")
game.ReplicatedStorage.BuyGem:FireClient(plr,true,"SUCCESSFULLY BOUGHT "..tostring(buyGemTable[v]).." GEMS!")
print("FIRED!")
end
end
local function processReceipt(receiptInfo)
local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
-- Determine if the product was already granted by checking the data store
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
local success, errorMessage = pcall(function()
purchased = marketData:GetAsync(playerProductKey)
end)
-- If purchase was recorded, the product was already granted
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
print("Data store error:" .. errorMessage)
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
end
-- Find the player who made the purchase in the server
if not plr then
-- The player probably left the game
-- If they come back, the callback will be called again
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
print("ERROR")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Look up handler function from 'productFunctions' table above
local handler = productFunctions[receiptInfo.ProductId]
-- Call the handler function and catch any errors
local success, result = pcall(handler, receiptInfo, plr)
if not success then
warn("Error occurred while processing a product purchase")
warn(result)
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", plr)
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Record transaction in data store so it isn't granted again
local success, errorMessage = pcall(function()
marketData:SetAsync(playerProductKey, true)
end)
if not success then
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
print("Cannot save purchase data: " .. errorMessage)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
CLIENT
t = confirmBuyGem.Yes.MouseButton1Click:Connect(function()
t:Disconnect()
print("CLICK BUY")
local productID = buyGemTable[tostring(gems)]
confirmBuyGem.Yes.Visible = false
confirmBuyGem.No.Visible = false
confirmBuyGem.Message.Visible = false
game:GetService("MarketplaceService"):PromptProductPurchase(player, productID)
confirmBuyGem.Processing.Visible = true
confirmBuyGem.Processing.BackgroundColor3 = Color3.fromRGB(255, 255, 127)
local buySuccess = false
local message = nil
confirmBuyGem.Ok.Visible = false
game.ReplicatedStorage.BuyGem.OnClientEvent:Connect(function(bool,msg)
print("ON EVENT")
buySuccess = bool
message = msg
print(bool)
print(msg)
end)
local waitTime = 0.3
local timeOut = 20
repeat
confirmBuyGem.Processing.Text = "PROCESSING . "
timeOut -= waitTime
wait(waitTime)
confirmBuyGem.Processing.Text = "PROCESSING . . "
timeOut -= waitTime
wait(waitTime)
confirmBuyGem.Processing.Text = "PROCESSING . . . "
timeOut -= waitTime
wait(waitTime)
until buySuccess or timeOut < 0 or message ~= nil
if not buySuccess then
confirmBuyGem.Processing.Text = "PURCHASING FAILED. PLEASE TRY AGAIN LATER."
confirmBuyGem.Processing.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
else
confirmBuyGem.Processing.Text = "PURCHASING SUCCESSFUL!"
confirmBuyGem.Processing.BackgroundColor3 = Color3.fromRGB(85, 255, 0)
end
if message then
confirmBuyGem.Processing.Text = message
end
confirmBuyGem.Ok.Visible = true
confirmBuyGem.Ok.MouseButton1Click:Connect(function()
confirmBuyGem.Visible = false
end)
wait(0.1)
debounceGem = false
end)
No changes made, just fixed the formatting.
The function connected to your OnClientEvent event handler is missing a parameter to handle the player instance. In other words, the player instance which is passed to FireClient() is passed to the first parameter received by the function connected to the OnClientEvent handle named “bool”, and the bool value of false you pass as the second argument to the FireClient() function call ends up being passed to the second parameter received by the function connected to the OnClientEvent event handler which is named “msg”.
So from:
game.ReplicatedStorage.BuyGem.OnClientEvent:Connect(function(bool,msg)
To:
game.ReplicatedStorage.BuyGem.OnClientEvent:Connect(function(plr,bool,msg)
But the thing is, isn’t the first parameter of the FireClient() supposed to be a player argument? For example,
--Server
remoteEvent:FireClient(plr,"Hello")
and then
--Client
remoteEvent.OnClientEvent:Connect(function(msg)
print(msg) -- hello
end)
Isn’t the player argument supposed to be included when fire server and when on client event it would be deleted right? Correct me if I’m wrong. THank you
ok i will i will it a try
char limit
it still didn’t work. I think it isn’t because of the argument because i also have a print(“ON EVENT!”) function so it should print the string even if the argument is wrong. I will try to demove the t:Disconnect()
If it doesn’t work then there’s likely some other issue occurring.
print(“ON EVENT”)
Does this line execute?
Make sure to check the console for any errors etc.
no, it doesn’t print it. but the server did print (“FIRE!”)
char limit
char limit
char limit
Yeah, just saw the previous reply, definitely something else going wrong then, still, you’ll need to keep the above change I mentioned.
Ok now it still doesn’t work. Idk why
No problem & let me know if that does fix it, thanks. You may want to move it to the end of the connected function, if you still want to keep it that is.
Ok i think the problem is with the fire server because I can’t really tell if it fired or not just because the lines were run, but, I have the exact same code for buying coins but with gems so i think it has something to do with the developer product. Here is full code on server
for i, v in pairs(buyGemTableName) do
productFunctions[tonumber(v)] = function(receipt, plr)
plr.Gems.Value += tonumber(buyGemTable[v])
print("BUY GEM") -- it prints
game.ReplicatedStorage.BuyGem:FireClient(plr,true,"SUCCESSFULLY BOUGHT "..tostring(buyGemTable[v]).." GEMS!")
print("FIRED!") -- it prints as well
end
end
local function processReceipt(receiptInfo)
local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
-- Determine if the product was already granted by checking the data store
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
local success, errorMessage = pcall(function()
purchased = marketData:GetAsync(playerProductKey)
end)
-- If purchase was recorded, the product was already granted
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
print("Data store error:" .. errorMessage)
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
end
-- Find the player who made the purchase in the server
if not plr then
-- The player probably left the game
-- If they come back, the callback will be called again
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
print("ERROR")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Look up handler function from 'productFunctions' table above
local handler = productFunctions[receiptInfo.ProductId]
-- Call the handler function and catch any errors
local success, result = pcall(handler, receiptInfo, plr)
if not success then
warn("Error occurred while processing a product purchase")
warn(result)
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", plr)
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Record transaction in data store so it isn't granted again
local success, errorMessage = pcall(function()
marketData:SetAsync(playerProductKey, true)
end)
if not success then
game.ReplicatedStorage.BuyGem:FireClient(plr,false)
print("Cannot save purchase data: " .. errorMessage)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
But none of the print functions worked **except ** the print(“FIRE”) and print(“BUY GEM”)
Add prints before each FireClient call.
YAY I MANAGE TO FIND THE SOLUTION. It was probably because the argument "SUCCESSFULLY BOUGHT "..tostring(buyGemTable[v]).." GEMS!"
had an error so it didn’t fire at all. ROblox should print out an error for this and not just keep it silent. But thank you for your help. have a nice day/night.
1 Like