-
What do you want to achieve?
I want to hav zero duplicates.
6 duplicated in dis vid and i dont no how
robloxapp-20210708-1822522.wmv (2.9 MB)
heres a module dictionary table thing
local questions =
{
[1] = {question = "1+1", answer = "2" },
[2] = {question = "2+2", answer = "4" },
[3] = {question = "3+3", answer = "6" },
[4] = {question = "4+4", answer = "8" },
[5] = {question = "6+6", answer = "12" },
[6] = {question = "7+7", answer = "14" },
[7] = {question = "8+8", answer = "16" }
}
And heres my entire script i used for what happned in the video above
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 questions 1-7
for _, v in pairs(quest) do
table.insert(randomAnswerTable, v.answer) --insertin all answers
print("THIS IS INSERTED"..v.answer)
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(table.remove(randomAnswerTable, table.find(randomAnswerTable, QuestionTable.answer))) -- remove the answer the loop is on from table
for _, v in pairs(parts) do --for all parts
print(QuestionTable.answer)
local otheranswers = randomAnswerTable[math.random(1,#randomAnswerTable)] --random answer
table.remove(randomAnswerTable, table.find(randomAnswerTable, otheranswers)) -- remove random from the table
v.SurfaceGui.TextLabel.Text = otheranswers --text = random
end
print(QuestionTable.answer)
local randompart = parts[math.random(1, #parts)] --Random part
randompart.SurfaceGui.TextLabel.Text = QuestionTable.answer --the right answer on a random part
print(QuestionTable.answer)
for _, v in pairs(randomAnswerTable) do
print("THIS IS DELETED"..v)
v = nil
end
local therightanswer = false
for _, v in pairs(parts) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and therightanswer == false then
if v.SurfaceGui.TextLabel.Text == QuestionTable.answer then
therightanswer = true
v.CanCollide = false
v.Transparency = 1
wait(2)
v.CanCollide = true
v.Transparency = 0.8
end
end
end)
end
repeat wait() until therightanswer == true -- waiting till answer has been chosen, then next question
print("YESYESYES")
therightanswer = false
print(QuestionTable.question .. "\n" .. QuestionTable.answer)
end
click link for Solution