Attempt to index nil with 'Button'

I made an ordering system for my cafe about a week ago. There is a gui that the player must type the customer’s username into. Recently, when the player types in the customer’s username and clicks continue, it shows this error.

Ever since this started happening, some of the functions of the script have stopped working. The localscript still works completely fine with the server. When I print the values in the server script, that also works just fine. Only the localscript has an error. I don’t know why this randomly started happening.

Just to make sure I didn’t accidentally mess up some of the values, I tried printing all of the data being sent back to the server. This worked just fine and all of the values are perfect still.

Here is some of the localscript.

(data[1] is the screen, data[2] is the player.)

ContinueButton.MouseButton1Click:Connect(function()
			if #TextBox.Text == 0 then
			else
				for i,v in pairs(Players:GetChildren()) do
					if v:IsA("Player") then
						if string.sub(string.lower(v.Name),0,string.len(TextBox.Text)) == string.lower(TextBox.Text) then
							MainFrame:TweenPosition(UDim2.new(0.5,0,-0.35,0), "Out", "Quint", 1)
							
							print(data[2],data[1],true,v)
							
							game.ReplicatedStorage.Ordering.OrderingFunction:InvokeServer(data[2],data[1],true,v)
							TextBox.Text = ""
							wait(1)
							clonegui:Destroy()
						end
					end
				end
			end
		end)

The code errors here,

game.ReplicatedStorage.Ordering.OrderingFunction:InvokeServer(data[2],data[1],true,v)

This is some of the script,

function orderingFunction.OnServerInvoke(...)
			local data = {...} --data[1] = player, data[2] = player, data[3] = screen, data[4] = cancel/continue, data[5] = customer
			if data[1] == nil then return 0 end
			if data[2] == nil then return 0 end
			if data[3] == nil then return 0 end
			if data[4] == nil then return 0 end
			print(data[1],data[2],data[3],data[3],data[4],data[5])
			if data[3] == screen then
				local BaristaUsing = screen:FindFirstChild("BaristaUsing")
				if BaristaUsing.Value == data[2].UserId then
					if data[4] == true then
						if data[5] == nil then return 0 end
						local customerusing = screen:FindFirstChild("CustomerUsing")
						customerusing.Value = data[5].UserId
						showscreen(screen,"Ordering",player)
						return
					else
						showscreen(screen,"SignedIn",player)
						return
					end
				end
			end
		end

After many times of looking at the localscript and script again, I can’t find any errors. I don’t even know how the button is part of the error when the data has nothing to do with the button.

2 Likes

Update: I fixed the error. For some reason the server script did not give me an error.