How to choose only one object from four?

Hello! I’m making a system where you can serve food!

I have four gui frames. These are orders.

They all have attributes set to them.

lol2

lol3

For example the first frame has carrots attribute, the second one has tomato attribute, the third one has tomato and fourth one has carrots.

Here’s the image representing what I mean.

lol4

I also have a plate that has this attribute.
lol3

lol5

And here’s my code!

local attributes = plate:GetAttribute("Foods") --getting the foods attribute from the plate
	local frames = game.StarterGui.OrderGUI.MainFrame:GetChildren() -- getting all the gui frames
	
	for _,frame in pairs(frames) do -- looping through the frames
		if frame.Name == "OrderFrame" then
			local orders = frame:GetAttribute("Foods") -- getting the foods attribute from the gui frames
			if orders == attributes then -- if gui attribute is equal to plate attribute then it's gonna print working else it's wrong order
				print("working")
			else
				print("wrong order")
			end
		end
	end

I want to serve only one order and the problem is that if i have two gui frames with carrots (image above) then it’s gonna serve two of them.

The same thing occurs with tomatoes. If I have i plate with tomatoes attribute then it’s gonna serve two frames

Any help is appreciated! :+1:

Don’t reference gui from StarterGui, instead reference it from LocalPlayer.PlayerGui

Also, addressing your main issue, just add a break

local attributes = plate:GetAttribute("Foods") --getting the foods attribute from the plate
local frames = LocalPlayer.PlayerGui.OrderGUI.MainFrame:GetChildren() -- getting all the gui frames
	
for _,frame in pairs(frames) do -- looping through the frames
	if frame.Name == "OrderFrame" then
		local orders = frame:GetAttribute("Foods") -- getting the foods attribute from the gui frames
		if orders == attributes then -- if gui attribute is equal to plate attribute then it's gonna print working else it's wrong order
			print("working")

            break --Wil cut off the loop
		else
			print("wrong order")
		end
	end
end

Thank you so much! Why didn’t I see this earlier.

The script is server sided so is it going to work on player gui?

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