Remote function not working properly

Hello! I need a hand, does anyone know what’s wrong?
I’m trying to make my RemoteFunction check if there is a tool with the same name as item1 and item2 from my orderData, and it’s throwing the following error in my output:

-- 16:12:53.392 - Delivery order button pressed - Client - OrdersLocalscriptManager:257 -- 16:12:53.392 - There are no items in the order or a template already exists. - Client - OrdersLocalscriptManager:239 -- 16:12:53.392 - Checking if order exists for username: Player2 - Client - OrdersLocalscriptManager:199 -- 16:12:53.392 - Order found for username: Player2 - Client - OrdersLocalscriptManager:202 -- 16:12:53.442 - Failed to deliver order: Player does not have required tools for the order - Client - OrdersLocalscriptManager:273

local-script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local deliverOrderFunction = ReplicatedStorage.remoteFunctions:WaitForChild("deliverOrderFunction")

-- Connect the MouseButton1Click event for the deliveryOrderButton
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
		-- Invoke the deliverOrderFunction on the server with the orderData
		local success, errorMessage = deliverOrderFunction:InvokeServer(orderData)
		if success then
			print("Order delivery successful.")
		else
			print("Failed to deliver order:", errorMessage)
		end
	else
		print("No order found for nearby customer:", nearbyCustomer)
	end
end)

server-script:

-- Get the RemoteFunction for delivering orders from the client
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local deliverOrderFunction = ReplicatedStorage.remoteFunctions:WaitForChild("deliverOrderFunction")

-- Handle the server invocation
deliverOrderFunction.OnServerInvoke = function(player, orderData)
	-- Print order details
	print("Item 1: " .. orderData.item1)
	print("Item 2: " .. orderData.item2)
	print("Total Price: $" .. orderData.totalprice)

	-- Get the player's tools
	local tools = {}
	for _, tool in pairs(player.Backpack:GetChildren()) do
		if tool:IsA("Tool") then
			tools[tool.Name] = tool
		end
	end

	-- Print player's tools
	print("Player's tools:")
	for toolName, _ in pairs(tools) do
		print(toolName)
	end

	-- Check if the player's tools match the items in the order
	if tools[orderData.item1] then
		if orderData.item2 == "" or tools[orderData.item2] then
			-- Player's tools match the items in the order
			print("Player's tools match the items in the order.")
			-- Add logic here to process the order delivery
			return true, "Order successfully delivered"
		else
			-- item2 is not present in the player's tools
			print("Item 2 is not present in the player's tools.")
			return false, "Player does not have required tools for the order"
		end
	else
		-- item1 is not present in the player's tools
		print("Item 1 is not present in the player's tools.")
		return false, "Player does not have required tools for the order"
	end
end

Everything works, there is no syntax errors, so you probably made something do a task that it’s not supposed to do or whatever. What’s exactly the issue though, looks like a normal function being calle dfor me

What happens is that in my starterplayer I put a tool called Burger and to test it I tried to check it and it didn’t work, it gives me that error, what could be wrong? :confused:

image:
image

Hey there! Big thanks for the assistance, but I ran into an unexpected snag in my code! Turns out, I had a bit of an overload handling all those remote events in my single LocalScript. So, what I did was create a dedicated LocalScript just for the delivery button, integrating the updated orders table. And you know what? It’s smooth sailing now. Appreciate your insights!

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