How to put answers on walls without duplicates

  1. What do you want to achieve?

I want to place answers on these parts without any duplicates.
image

  1. What is the issue?
    I’m a banana who is for some reason unable to place answers on a wall without any duplicates.

  2. What solutions have you tried so far?

for i = 1, 7 do --for questions 1 to 7
	
	local QuestionTable = quest[i]
	text = QuestionTable.question
	local length = string.len(text) --Question comes up
	
	script.Sound:Play()
	
	for i = 1, length do
		QuestionText.Text = text:sub(1, i)
		wait(0.04)
		if i > 35 then
			script.Sound:Stop()
		end
	end
	
	
	local randompart = parts[math.random(1, #parts)] --Random answer wall
	randompart.SurfaceGui.TextLabel.Text = QuestionTable.answer --the right answer on a random part
	
	
	
	for i, v in pairs(parts) do  --all answewr walls
		if v.SurfaceGui.TextLabel.Text ~= QuestionTable.answer then -- if text wall not answer then
			local otheranswers = randomAnswerTable[math.random(1, #randomAnswerTable)] --random answer
			
			if otheranswers ~= QuestionTable.answer then --if random answer is not correct answer then
				
				v.SurfaceGui.TextLabel.Text = otheranswers
				
			end
		end
	end

The below is what happened after editing the above.

local parts = game.Workspace:WaitForChild("Answers"):GetChildren()


local randomAnswerTable = {}

for i, v in pairs(quest) do
	table.insert(randomAnswerTable, v.answer) --just to place random answers
end

local emptyTable = {}




for i = 1, 7 do --for questions 1 to 7

	local QuestionTable = quest[i]
	text = QuestionTable.question
	local length = string.len(text) --Question comes up

	script.Sound:Play()

	for i = 1, length do
		QuestionText.Text = text:sub(1, i)
		wait(0.04)
		if i > 35 then
			script.Sound:Stop()
		end
	end


	local randompart = parts[math.random(1, #parts)] --Random answer wall
	randompart.SurfaceGui.TextLabel.Text = QuestionTable.answer --the right answer on a random part
	print("yeeeeee"..QuestionTable.answer)

	for i, v in pairs(parts) do  --all parts
		
			local otheranswers = randomAnswerTable[math.random(1, #randomAnswerTable)] --random answer
			
		if otheranswers == QuestionTable.answer and table.find(emptyTable, otheranswers) then --if random answer is not correct answer then
			repeat
				wait(3)
				otheranswers = randomAnswerTable[math.random(1, #randomAnswerTable)]
				table.insert(emptyTable, 1, otheranswers)
				print("is RANDOMIZING")
			until not table.find(emptyTable, otheranswers)

		else
			v.SurfaceGui.TextLabel.Text = otheranswers 
			table.insert(emptyTable, 1, otheranswers)
			
				
			print("BingBong")
				
				
				
			
		end
	end

The below is my last attempt, still didn’t work.

local sss = game:GetService("ReplicatedStorage")
local quest = require(sss.question) 

local QuestionText = script.Parent
local text

local parts = game.Workspace:WaitForChild("Answers"):GetChildren()


local randomAnswerTable = {}





for i = 1, 7 do
	
	for i, v in pairs(quest) do
		table.insert(randomAnswerTable, v.answer) --just to place random answers
	end
	
	local QuestionTable = quest[i]
	text = QuestionTable.question
	local length = string.len(text) --Question comes up
	
	script.Sound:Play()
	
	for i = 1, length do
		QuestionText.Text = text:sub(1, i)
		wait(0.04)
		if i > 35 then
			script.Sound:Stop()
		end
	end
	
	print(QuestionTable.answer)
	local randompart = parts[math.random(1, #parts)] --Random answer wall
	randompart.SurfaceGui.TextLabel.Text = QuestionTable.answer --the right answer on a random part
	
	
	
	for i, v in pairs(parts) do  --all answewr walls
		if v ~= randompart then
			
			table.remove(randomAnswerTable, #QuestionTable.answer)
			local otheranswers = randomAnswerTable[math.random(1, #randomAnswerTable)] --random answer
			table.remove(randomAnswerTable, randomAnswerTable[otheranswers])
			
				
				v.SurfaceGui.TextLabel.Text = otheranswers
				
			end
		end
	
	for i, v in pairs(randomAnswerTable) do
		
		print(v)
		v = nil
		
	end
	

click link for solution

1 Like
local answers = {"Yes", "No", "Maybe", "Never", "Ok fine"}
local displayed = {}

function createAnswer()
	local newAnswer
	repeat wait()
		newAnswer = answers[math.random(1,#answers)]
	until not displayed[newAnswer] -- this part right here loops till it is no longer a displayed answer
	displayed[newAnswer] = true
	print(newAnswer)
end
for i = 1,#answers do
	createAnswer()
end