Help with RemoteEvents not handling data properly

I’m trying to make an order system, it’s going somewhat well until I got to the queue part and whatnot, so essentially, a variable called ‘staffMember’ is generated and it’s set to the first person in the queue. Now I want the staffMember to have gui that appears on their screen, However, when I fire the client and send the staff member, it appears on the client as nil. Code is below, both serverside and local side.

Server side:

game.ReplicatedStorage.OrderSubmitted.OnServerEvent:Connect(function(player, orderInfo, ordersTarget)
	local submittedPlayer = player

	local staffMember = nil

	if #orderQueue > 0 and debounce == false then
		debounce = true
		staffMember = orderQueue[1]
		table.remove(orderQueue, 1)

		print(orderInfo)
		print(staffMember, "-staffmember1")

		for i, remainingPlayer in ipairs(orderQueue) do
			game.ReplicatedStorage.UpdateQueuePosition:FireClient(remainingPlayer, i)
		end
	end

	local ticketNum = currentTicket + 1
	currentTicket = ticketNum

	if staffMember then
		local char = game.Workspace:FindFirstChild(ordersTarget)
		local ticketNumDisplay = script.TicketNumDisplay:Clone()
		ticketNumDisplay.Frame.Name1.Text = "Ticket #" .. ticketNum
		ticketNumDisplay.Parent = char:WaitForChild("Head")
	end

	print(staffMember, "-staffmember2")

	game.ReplicatedStorage.OrderRecieved:FireClient(player, staffMember, orderInfo)

	wait(0.5)
	debounce = false

	return staffMember
end)

Local Script:

game.ReplicatedStorage.OrderRecieved.OnClientEvent:Connect(function(staffMember, orderInfo)
	local localPlayer = game.Players.LocalPlayer
	print(localPlayer.Name)
	print(staffMember)
	if localPlayer.Name == staffMember then
		notiText.Text = "Order Received!"
		notificationFrame.Visible = true
		notiSlideIn(notificationFrame)

		orderDisplayFrame.Visible = true
		orderSlideIn(orderDisplayFrame)

		if type(orderInfo) == "table" then
			for key, itemFrame in ipairs(itemFrameHolder) do
				local orderIndex = key - 1  -- Adjust the index to match Lua indexing
				if itemFrame:IsA("TextLabel") and orderInfo[orderIndex] then
					itemFrame.Text = orderInfo[orderIndex]
				end
			end
		else
			print("Received orderInfo is not a table.")
		end

		addItemButton.MouseButton1Click:Connect(function()
			if itemsAdded < #orderInfo then
				itemsAdded = itemsAdded + 1
				local tool = staffMember.Character:FindFirstChildOfClass("Tool")

				if tool then
					local itemName = tool.Name
					print(itemName)

					for key, itemFrame in ipairs(itemFrameHolder) do
						if itemFrame:IsA("TextLabel") then
							if itemFrame.Text == itemName then
								tool:Destroy()

								itemFrame.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
								break
							end
						end
					end
				end
				if itemsAdded == #orderInfo then
					addItemButton.Text = "Submit"
				end
			elseif itemsAdded == #orderInfo then
				orderSlideOut(orderDisplayFrame)

				for key, itemFrame in ipairs(itemFrameHolder) do
					if itemFrame:IsA("TextLabel") then
						wait(1)
						itemFrame.BackgroundColor3 = Color3.new(1, 1, 1)
						break
					end
				end

				addItemButton.Text = "Add Item"

				print('Order submitted!')
			end
		end)

		wait(3)
		notiSlideOut(notificationFrame)
	end
end)

Am I doing this right or is there a better way to get the gui to appear on the staffmembers screen? The only way that was working for me was sending the ‘player’ (the player that created the order) as well, and I’m not sure why. I hope you can point out my errors.

2 Likes

Could you send a screenshot of where it is erroring or not working?

1 Like

It’s not necessarily erroring, it’s just that the code will print something like ‘player1’ for the staffMember the first time, and then print again as ‘nil’ for the staffMember. I’ve linked the important parts of the code below. None of the notiText or anything below that is working on the client script.

Below is the important parts within the server sided script.

game.ReplicatedStorage.OrderSubmitted.OnServerEvent:Connect(function(player, orderInfo, ordersTarget)
	local submittedPlayer = player

	local staffMember = nil

	if #orderQueue > 0 and debounce == false then
		debounce = true
		staffMember = orderQueue[1]
		table.remove(orderQueue, 1)

		print(orderInfo)
		print(staffMember, "-staffmember1")

		for i, remainingPlayer in ipairs(orderQueue) do
			game.ReplicatedStorage.UpdateQueuePosition:FireClient(remainingPlayer, i)
		end
	end

game.ReplicatedStorage.OrderRecieved:FireClient(player, staffMember, orderInfo)

shouldn’t player be staff member? because you are trying to make the gui appear on the staff’s screen not on the players screen

[EDIT]

idk whats going on with staff member being nil tho

2 Likes

Honestly, I still don’t really know exactly what was going on, but I do know you had a good point about the staffmember, I changed that and all of a sudden it’s working now, it’s still printing nil but it’s working as intented so it’s functional. Not sure how but hey, if it’s not broken I’m not going to try to fix it.

1 Like

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