Remote Event not firing

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to have a remote event to clone and re-parent an object when fired.
  2. What is the issue? Include screenshots / videos if possible!
    The remote event simply wont fire. (The rest of the local script runs fine)
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked at previous devforum posts and requested help on RSC.

Client

local MPS = game:GetService("MarketplaceService")
local RS = game:GetService("ReplicatedStorage")

local event = RS:WaitForChild("BoughtItem")

local player = game:GetService("Players").LocalPlayer

for i, button in ipairs(script.Parent:GetChildren()) do
	if button:IsA("TextButton") then
		button.MouseButton1Click:Connect(function()
			if button:FindFirstChild("PurchaseID") then
				MPS:PromptProductPurchase(player,button.PurchaseID.Value)

				MPS.PromptProductPurchaseFinished:Connect(function(playerID, productID, purchased)
					if purchased then
						print("purchased")
						event:FireServer(button.Name)
					end
				end)
			end
		end)
	end
end

Server

local RS = game:GetService("ReplicatedStorage")
local event = RS:FindFirstChild("BoughtItem")

event.OnServerEvent:Connect(function(player, itemName)
	print("fired")
    local tool = game.ServerStorage.Assets:FindFirstChild(itemName):Clone()
    tool.Parent = player.Backpack
end)

My output prints “purchased”, but never “fired”

event.OnServerEvent:Connect(function(player, itemName)
event.OnServerEvent:Connect(function(player, itemName)
event.OnServerEvent:Connect(function(player, itemName)
	print("fired")
    local tool = game.ServerStorage.Assets:FindFirstChild(itemName):Clone()
    tool.Parent = player.Backpack
end)

Why is there 3 of the same line?

I don’t know, but its not in the actual code. I’ll fix it here

PromptProductPurchaseFinished this event does not fire to the client I believe and should really be used on a server side script. So in a server script you need on single event that listens for these signals, and then process that in a single script.

But the purchase prompt shows up fine on the client.

OK, understood. I still think that the event would be best caught on the server, as the client could easily spoof remote and obtain the item. Try changing the serverside script to capture the event instead:

MPS.PromptProductPurchaseFinished:Connect(function(playerID, productID, purchased)
	if purchased then
		print("purchased"), playerID, 
		local tool = game.ServerStorage.Assets:FindFirstChild(itemName):Clone()
		tool.Parent = player.Backpack
	end
end)

As an after thought, have you confirmed that RS:FindFirstChild("BoughtItem") is a RemoteEvent? Sometimes it’s easy to overlook the obvious.

Changing the prompt to the server doesn’t help, as now the prompt won’t even appear. And yes, BoughtItem is a RemoteEvent.

@BadDad2004 Do you have any other solutions for this?

Hi, I have read from others on DevForum that they have had issues with new RemoteEvents. You could try recreating the remote itself and see if that resolves the matter. Other than that, they are supposed to be fairly straight forward to use, so not sure how to guide you further.

local event = RS:FindFirstChild("BoughtItem")

Try switching this to RS:WaitForChild in the server script.
Also, server-side, verify the connect is hooked up by doing a print just before it.

Something like

print('hooking up', event.Name)
event.OnServerEvent:Connect(function(player, itemName)
	print("fired")
    local tool = game.ServerStorage.Assets:FindFirstChild(itemName):Clone()
    tool.Parent = player.Backpack
end)

Hey everyone, found my issue. It was the server’s end. For whatever reason, the script couldn’t detect when the RemoteEvent was getting fired from the workspace, so I moved the script to ServerScriptService and edited it.

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