Code issues FireServer isn't executing properly

Hello! I need a hand, does anyone know why my FireServer isn’t executing properly? What’s wrong with my code? :pray:

localscript:

deliveryOrderButton.MouseButton1Click:Connect(function()
	-- Handle the delivery order button click
	print("Delivery order button pressed")

	-- Get the order data and process the order
	local orderData = saveOrderData()
	processOrder(orderData)

	-- Check if there is an order for the nearby customer
	local nearbyCustomer = checkNearbyCustomer() 
	local orderExistsForCustomer = checkOrderExists(nearbyCustomer) 

	if orderExistsForCustomer then
		-- Print the order details if an order exists for the nearby customer
		print("Order found for nearby customer:", nearbyCustomer)
		print("")
		for _, order in pairs(orders) do
			if order.username == nearbyCustomer then
				print("Order Details:")
				print("Username:", order.username)
				print("Item 1:", order.item1)
				print("Item 2:", order.item2)
				print("Total Price:", order.totalprice)
				break
			end
		end

		-- Fire the deliverOrderEvent with the order details as parameters
		local deliverOrderEvent = game:GetService("ReplicatedStorage").remoteEvents:WaitForChild("deliverOrderEvent")
		deliverOrderEvent:FireServer(orderData)
	else
		print("No order found for nearby customer:", nearbyCustomer)
	end
end)

serverscript:

local deliverOrderEvent = game:GetService("ReplicatedStorage").remoteEvents:WaitForChild("deliverOrderEvent")

deliverOrderEvent.OnServerEvent:Connect(function(player, orderData)
	print("Received order data from the server by:", player.Name)
	print("Order Data:")
	print("Username:", orderData.username)
	print("Item 1:", orderData.item1)
	print("Item 2:", orderData.item2)
	print("Total Price:", orderData.totalprice)
end)
3 Likes

Make sure you aren’t passing any instances along the RemoteEvent. Are there any errors in the output?

1 Like

No error appears in the console and the server side prints are not printed either, it’s like it ignores the fire server or something like that

2 Likes

Try restarting the server you’re testing in. If it’s studio, restart studio. It just could be a bug.

2 Likes

I tried it and it still doesn’t work. I also used pcall and it sends to the server, but the server doesn’t respond with the print.

localscript:

deliveryOrderButton.MouseButton1Click:Connect(function()
	print("Delivery order button pressed")

	local orderData = saveOrderData()
	processOrder(orderData)

	local nearbyCustomer = checkNearbyCustomer() 
	local orderExistsForCustomer = checkOrderExists(nearbyCustomer) 

	if orderExistsForCustomer then
		print("Order found for nearby customer:", nearbyCustomer)
		print("")
		for _, order in pairs(orders) do
			if order.username == nearbyCustomer then
				print("Order Details:")
				print("Username:", order.username)
				print("Item 1:", order.item1)
				print("Item 2:", order.item2)
				print("Total Price:", order.totalprice)

				print("Sending order data to server:")
				print(order)

				local deliverOrderEvent = game:GetService("ReplicatedStorage").remoteEvents:WaitForChild("deliverOrderEvent")
				local success, error = pcall(function()
					deliverOrderEvent:FireServer({
						username = order.username,
						item1 = order.item1,
						item2 = order.item2,
						totalprice = order.totalprice
					})
				end)
				if not success then
					warn("Error sending order data to server:", error)
				end
				break
			end
		end
	else
		print("No order found for nearby customer:", nearbyCustomer)
	end
end)

server script:

local deliverOrderEvent = game:GetService("ReplicatedStorage").remoteEvents:WaitForChild("deliverOrderEvent")

deliverOrderEvent.OnServerEvent:Connect(function(player, orderData)
	local success, error = pcall(function()
		print("Received order data from the server by:", player.Name)
		print("Order Data:")
		for key, value in pairs(orderData) do
			print(key, ":", value)
		end
	end)

	if not success then
		warn("Error processing order data:", error)
	end
end)

console output:

 19:24:03.262  Delivery order button pressed  -  Client - OrdersLocalscriptManager:253
  19:24:03.263  There are no items in the order or a template already exists.  -  Client - OrdersLocalscriptManager:239
  19:24:03.263  Checking if order exists for username: Player2  -  Client - OrdersLocalscriptManager:199
  19:24:03.263  Order found for username: Player2  -  Client - OrdersLocalscriptManager:202
  19:24:03.263  Order found for nearby customer: Player2  -  Client - OrdersLocalscriptManager:265
  19:24:03.263    -  Client - OrdersLocalscriptManager:266
  19:24:03.263  Order Details:  -  Client - OrdersLocalscriptManager:269
  19:24:03.263  Username: Player2  -  Client - OrdersLocalscriptManager:270
  19:24:03.263  Item 1: Soda  -  Client - OrdersLocalscriptManager:271
  19:24:03.264  Item 2: Water  -  Client - OrdersLocalscriptManager:272
  19:24:03.264  Total Price: 3  -  Client - OrdersLocalscriptManager:273
  19:24:03.264  Sending order data to server:  -  Client - OrdersLocalscriptManager:276
  19:24:03.264   ▶ {...}  -  Client - OrdersLocalscriptManager:277

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