- What do you want to achieve?
I want to place answers on these parts without any duplicates.
-
What is the issue?
I’m a banana who is for some reason unable to place answers on a wall without any duplicates. -
What solutions have you tried so far?
Heres my last try
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) --insert all answers into table
end
local QuestionTable = quest[i]
text = QuestionTable.question
local length = string.len(text) --Question comes up on gui
script.Sound:Play()
for i = 1, length do
QuestionText.Text = text:sub(1, i)
wait(0.04)
if i > 35 then
script.Sound:Stop() --for stuff to com on gui
end
end
print(QuestionTable.answer)
local randompart = parts[math.random(1, #parts)] --random part
randompart.SurfaceGui.TextLabel.Text = QuestionTable.answer --change that parts text to right answer.
--Am i doing somethin obviously wrong in the loop below.
for i, v in pairs(parts) do --all parts
if v ~= randompart then -- if the part isnt the random part chosen above
table.remove(randomAnswerTable, #QuestionTable.answer) --remove actual answer from table. THIS IS WRONG, WAT IS RIGHT
local otheranswers = randomAnswerTable[math.random(1, #randomAnswerTable)] --random answer from table
table.remove(randomAnswerTable, randomAnswerTable[otheranswers]) --remove random answer from table
v.SurfaceGui.TextLabel.Text = otheranswers --the parts text becomes other answer
end
end
for i, v in pairs(randomAnswerTable) do -- empty the table
print(v)
v = nil
end