If Player Has Selected ALL 6 Correct Boxes

Hello, I’m wanting to make a mini game where the player has to select all of the 6 boxes correctly.

I’m having issues on finding if the player selected the boxes. And if the player has selected the correct boxes it prints something like “Well Done” or something like that.

Here’s my current code on randomizing the boxes:

local GUIs = script.Parent.Frame:GetChildren()
local RandomNumber = math.random(1, #GUIs)
local Selected = {}

while task.wait() do
	if Selected[6] then
		break
	else
		if table.find(Selected, GUIs[RandomNumber], 1) then
			RandomNumber = math.random(1, #GUIs)
		else
			table.insert(Selected, GUIs[RandomNumber])
			GUIs[RandomNumber].BackgroundColor3 = Color3.fromRGB(255,  0, 0)
			RandomNumber = math.random(1, #GUIs)
		end
	end
end


-- take them back to normal state after seeing them
wait(2)
Selected[1].BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Selected[2].BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Selected[3].BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Selected[4].BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Selected[5].BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Selected[6].BackgroundColor3 = Color3.fromRGB(255, 255, 255)

Could you tell me what are the “issues” you’re talking about?

So basically, you have a bunch of GUIs that 6 of them change to red, then all of them change back to white, and the player has to select the 6 that were red?
Have textbuttons on each Gui.
You already have the values of the Guis that turned red in the Selected table.
Check to see if when the player clicks each button that the button clicked is in the Selected table, then delete it from the table.
If the table is empty after the selection process, then “yay”, and if not, then “Sorry. You failed this minigame miserably”`

My issue is that I don’t know how to find out if the player selected the correct red boxes

They are all TextButtons within a Frame called “SelectedBoxes”, after a Box is selected it changes colour and parents to the “SelectedBoxes” frame.

How would I check to see if the box is in the “Selected” table though?

i think like this?

if Selected[SelectedBoxes.TextButton] then
-- stuff
end

Could you show me the explorer? i didn’t really get it.

Seems like I answered this already…

Here’s the explorer:
image

I didn’t understand much of it.

My issue is that I don’t know how to find out if the player selected the correct red boxes

are you wondering how to code it?

–server code psuedo explanation

you have a table with tables inside and those inner tables have tables to contain player names

the inside tables should represent their client side counterpart the chosen target boxes and be indexed as such.

whenever a player fires their end selection–for loop through the tables and add their name within the inner table’s table if the selectionindex matches the corresponding table index

validate if player exists in all chosen targets then they have selected all the boxes

edit: unfortunately i am not at my main comp so i cannot write code

I’m confused as to how to code it. Words aren’t making sense to me.

You’ve already put the red box GUI values into a table called Selection, so for example the random GUIs in the table are 1,2,4,5,8,9.
When a player clicks a GUI button check to see if that button value is inside the Selection table.
When each GUI button is clicked (lets say they click #4) then subtract 4 from the table.
When they check the next button, if it’s correct, subtract it from table as well.
When they’ve selected 6 buttons, check to see if the table is empty.
If the table is empty, then they’ve chosen the right 6 buttons. You can congratulate them and code whatever the reward is.
If the table still has GUI values in it, then they didn’t press the right 6 buttons, and you can make them do the level over, or kill them or whatever your result is.

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