Remote Event Data Table Transfer Issue

Hello! Encountering a problem while transferring data tables via RemoteEvents from a client LocalScript to a server ServerScript. Despite correctly formatting and sending the data, the server receives nil values for the parameters. :pray:

image

localscript:

local function orderCheck()
	-- Get the LocalPlayer
	local player = Players.LocalPlayer

	-- Check if the LocalPlayer exists
	if player then
		-- Get the username of the player
		local playerName = player.Name

		-- Check the selected items in the buttons
		local selectedItems = {}
		for _, button in ipairs(clickedButtons) do
			table.insert(selectedItems, button.Text)
		end

		-- Get the amount of CB
		local totalCost = calculateTotalPrice()

		-- Print the order information for debugging
		print("Player: " .. playerName)
		print("Selected Items: " .. table.concat(selectedItems, ", "))
		print("Total Cost: " .. totalCost)

		-- Fire a RemoteEvent to the server with the order information
		ReplicatedStorage.remoteEvents:WaitForChild("orderInformationEvent"):FireServer(playerName, selectedItems, totalCost)
	else
		print("LocalPlayer not found.")
	end
end

server-Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local tableFolder = script.Parent.Table
local chairsFolder = script.Parent.Chairs
local deliverAreaBoxesFolder = script.Parent.deliverAreasBoxes

local remoteEvent = ReplicatedStorage.remoteEvents:WaitForChild("orderInformationEvent")

remoteEvent.OnServerEvent:Connect(function(username, selectedItems, totalCost)
	if username and selectedItems and totalCost then
		-- Create a customer user object with the received data
		local customerUser = {
			username = username,
			item1 = selectedItems[1],
			item2 = selectedItems[2],
			totalCost = totalCost
		}

		-- Example: Print the customer user object for debugging
		print("Received order from customer:", customerUser.username)
		print("Selected Item 1:", customerUser.item1)
		print("Selected Item 2:", customerUser.item2)
		print("Total Cost:", customerUser.totalCost)

	else
		print("Received invalid data from the client.")
	end
end)

I need a hand with this, I haven’t managed to make it work properly. :pray:

OnServerEvent’s first value is always the player.

remoteEvent.OnServerEvent:Connect(function(player,username, selectedItems, totalCost)

1 Like

Lol! I forgot about that, thank you so much! I guess with a lot of programming, those small details slip my mind sometimes. Thanks!

1 Like

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