How would i make a question system?

Hi.
Recently i’ve been working on a new gam- “experience” called: The Question Games
It’s actually a game where you answer the most questions to win.
Get 1 wrong, your OUT!

So what i want to make is:
You get the most questions right, you win.

Get one wrong, you lose.

So what i want it to do is create a UI where they can answer questions, then, the winner is shown. How would i achieve this?

(i already have the code for the wrong answer script dont think about it)

4 Likes

To begin with, the server would randomly generate the question and send a request to every client using a remoteEvent, or a stringValue would be updated containing the question, however the first option tends to be better.

You’d use some sort of Image/Text Button for both Yes and No and make a variable for the answer. After that, there’d be 2 events for MouseButton1Down or something similar to register the input and note the answer in the previous variable. These events would now no longer work to prevent multiple answers.

Finally, a remoteEvent would then be fired back to the server with this value and the server would check if it’s equal to the questions answer.

1 Like

Script example?

no cookies for u if you steal this comment

1 Like

Sorry, I don’t have a script example for this.

1 Like

oof

I really dont know what your saying …

What don’t you understand about it? Does it lack depth, visual examples or just clarity in general?

I’m not really a advanced advanced scripter. so basically…

everything.

1 Like

Well uh, Required Lego- Imean Roblox Pieces:
RemoteEvent, LocalScript, ServerScript, ScreenGui, Frame, Button, Button, ClickEvent, AnswerCheckFunction.
Yeah this is kinda going to take some effort. But its pretty simple!
I assume you want Everyone to answer a question in the given time.
Add a RemoteEvent to ReplicatedStorage and Rename it to "QuestionEvent"
Now creative the be you must, and make a simple UI for the questionairez.
Not the buttons though, we shall make a script for that.
Do something Like: ScreenGui → Frame → {QuestionTextLabel at the top, AnswerFrame}
Add the AnswerFrame to where you want your buttons to be! So where the Answers/Choices will be displayed! Rename it to "AnswerFrame" Rename QuestionTextLabel to " QuestionLabel"
Add A UIListLayout to the AnswerFrame and set its offset to 10 and set other properties to your liking!
Add a TextButton, Set its Visible property to False, Rename it to AnswerOption, Move it to ReplicatedStorage!
Add a module script to the ScreenGui, Rename It to "QuestionModule" and Add the following code:

ModuleCode

Actually whatever I made it for you jsut use this:

Made by me you can trust me bro!
BRUV IVE BEEN ON THIS FOR 4 HOURZ WHAT

IMAGE

AW MAN CAN YOU ATLEAST TRY IT oopz caoz, ITZ 3AMBTW WAT AM I DOING WITHMY LIFE
ok goodn1ght

hope this helped the model is for learning purposes but really i finished the whole darn project for ya, kinda!

The Server Script:

IMAGE

image

EDIT It to your liking b y adding more questionz, I understand your not advanced at scripting

but no becz u can be anyth1ng! FIRST LINES!


:
image
THIS IMAGE SHOWS THE QUESTIONS
TO ADD A 3RD QUESTION DO THIS:
Data.Questions[3] = “YOUR QUESTION HERE?”
BELOW THAT CODE
AND TO ADD A FOURTH QUESTION DO THIS:
Data.Questions[4] = “YOUR QUESTION HERE?”
YEAH ANDNOW:
image
CHANGE THE HOWMANY ROUNDS TO HOW MANY QUESTIONS YOU HAVE ADDED, VERY IM[PORTANT!
TIMEFOREACH QESUTION IS HOW LONG A PERSON GETS ON EACH QUESTION
AND NOW THE COMPLICATED PART TO TEACH:

POSSIBLE ANSWERS AND THE CORRECT ANSWER
SIMILAR TO ABOVE, Data.Questions[4] = “YOUR QUESTION HERE?”
DO THE SAME THING BUT LIKE:
Data.TableAnswers[THEQUESTIONYOUAREEDITINGHERE] = {“POSSIBLE ANSWER 1”,“POSSIBLE ANSWER2”} ADD THE COMMA TO SEPERATE INSIDE THE {} CURLY BRACKETS AND ADD ASMANY ANSWERS AS YOU WANT BUT 4 IS RECCOMENDED AS A MAXIMUM LIMIT
NOW FOR THE ANSWERS:
YOU MUST COPY AND PASTE THE CORRECT ANSWER FROM THE POSSIBLE ANSWERS YOU HAVE PROVIDED FOR EXAMPLE FROM THE CODE ABOVE I COULD EITHER SAY
Data.TableAnswers[1] = “POSSIBLE ANSWER2” or ""POSSIBLE ANSWER 1"
YEAH ANYTHING ELSE WILL ERROR EVEN A SMALL SPELLING MISTAKE! SO COPY AND PASTE THE ANSWER!
image
NOW LIKE ABOVE U CAN ADD MROE, ANY FURTHER HELP CONTACT ME AND I WILL REPLY NOT SO SOON!SORRY for being like this im tired! have a goodday-n1ght, bye

NOT DONE FURTHERMORE, WANNA CHANGE DESCRIPTIONS OF WHAT YOU GET WHEN YOU GET A CORRECT OR INCORRECT ANSWER?


IN THE MODULE SCRIPT
image
CHANGE THE FIRST FEW LINES/!
LIKE ABOVE
local DescriptionTextOptions_Incorrect = {“Better Luck Next Time”, “At Least you tried”}
ADD AS MANY POSSIBLE OUTCOMES AS YOU WOULDLIKE! SEPERATED BYA COMMA
EXAMPLE TO ADD THE OUTCOME “HAHAHAH NOOB YOU LOST!” YOU DO:
local DescriptionTextOptions_Incorrect = {“Better Luck Next Time”, “At Least you tried”,“HAHA NOOB YOU LOST!”} liket hat ok bye

5 Likes

Your module code is blank-

justagamedeveloper1 made this comment

1 Like

oh- In that case, for the QuestionModule only copy and pastethis code:

local DescriptionTextOptions_Incorrect = {"Better Luck Next Time", "At Least you tried"}
local DescriptionTextOptions_Correct = {"Well done!", "You sussy baka 😳!"}

local Module = {}
local ScreenGui = script.Parent
local Frame = ScreenGui:WaitForChild("Frame")
local AnswerFrame, QuestionLabel = Frame:WaitForChild("AnswerFrame"), Frame:WaitForChild("QuestionLabel")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local QuestionEvent = ReplicatedStorage:WaitForChild("QuestionEvent")
local AnswerOption = ReplicatedStorage:WaitForChild("AnswerOption")
local AfterFrame = ScreenGui:WaitForChild("AfterFrame")
function Module.AskQuestion(TableAnswers,CorrectAnswer,QuestionText)
	local Answer = table.find(TableAnswers,CorrectAnswer,1)
	if not Answer then warn("Make sure the answer exists or the answer is inside the table") return end
	QuestionLabel.Text = QuestionText
	local Answered, AnswerCorrect = nil, false
	local Disconnect = false
	ReplicatedStorage:WaitForChild("UIListLayout"):Clone().Parent = AnswerFrame
	local Debounce = false
	for _, question in ipairs(TableAnswers) do
		local function Button()
			local CloneAnswer = AnswerOption:Clone() CloneAnswer.Parent = AnswerFrame
			CloneAnswer.Text = tostring(question)
			local function DisconnectFunc()
				repeat task.wait(1) until Disconnect
				AnswerClicked:Disconnect()
			end coroutine.wrap(DisconnectFunc)()
			AnswerClicked = CloneAnswer.MouseButton1Click:Connect(function()
				if Debounce then return end Debounce = true
				if string.lower(question)==string.lower(CorrectAnswer) then warn(question,CorrectAnswer,"EEEEE") AnswerCorrect = true else AnswerCorrect = false end
				task.wait(1) Answered = true Disconnect = true
				Module.Reset()
			end)
		end coroutine.wrap(Button)()
	end
	warn(Answered,AnswerCorrect)
	repeat task.wait(1) until Answered warn(Answered,AnswerCorrect)
	task.wait(1) return AnswerCorrect
end
function Module.CheckAnswer(RecievedAnswer,CorrectA)
	if string.lower(RecievedAnswer) == string.lower(CorrectA) then return true else return false end
end
function Module.FireEvent(_Qualified)
	if _Qualified then QuestionEvent:FireServer(true) elseif not _Qualified then QuestionEvent:FireServer(false) end
end
function Module.Reset()
	AnswerFrame:ClearAllChildren()
end
function Module.FrameScreen(_Incorrect_Wrong,_Timeout)
	AfterFrame.Visible = true
	if _Incorrect_Wrong then AfterFrame.BackgroundColor3 = Color3.fromRGB(255,100,100) AfterFrame:WaitForChild("Label").Text = "Incorrect" AfterFrame:WaitForChild("Description").Text = DescriptionTextOptions_Incorrect[math.random(1,#DescriptionTextOptions_Incorrect)] else AfterFrame.BackgroundColor3 = Color3.fromRGB(100,255,100) AfterFrame:WaitForChild("Label").Text = "Correct!" AfterFrame:WaitForChild("Description").Text = DescriptionTextOptions_Correct[math.random(1,#DescriptionTextOptions_Correct)] end
	task.wait(_Timeout)
	AfterFrame.Visible = false
end
return Module

image

In the case QuestionScript Broke, Not the module: Copy and paste this code:

local Data = {}
Data.TimeForEachQuestion = 10 -- how long is each question/round
Data.HowManyRoundsAltogether = 2 -- BTW Make a question for every round

Data.Questions = {}
Data.Questions[1] = "Question1" -- edit the question
Data.Questions[2] = "Question2" -- edit the question
-- add more, make enough for all the rounds!
Data.TableAnswers, Data.TableCorrectAnswers = {}, {}
Data.TableAnswers[1] =
	{"QuestionAnswerOption1","AddMoreOptionsLikeThis","E","this is the correct answer"} -- add as many questionas as you would like!
Data.TableCorrectAnswers[1] = "this is the correct answer" -- copy and paste the correct answer from the questions table
Data.TableAnswers[2] =
	{"Question2AnswerOption1","Definetely the Wrong Answer"}
Data.TableCorrectAnswers[2] = "Definetely the Wrong Answer"
-- add morelike above shown!

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StartEvent = ReplicatedStorage:WaitForChild("StartEvent")
local QuestionEvent = ReplicatedStorage:WaitForChild("QuestionEvent")
local ResetEvent = ReplicatedStorage:WaitForChild("ResetEvent")
local TableContestants = {}
local function RoundBegin(_Q,_Answers,_C_Answer)
	for _, player in ipairs(TableContestants) do StartEvent:FireClient(player) QuestionEvent:FireClient(player,_Q,_Answers,_C_Answer,tick()+Data.TimeForEachQuestion) end
end

local function CheckEventFire(_Q,_Answers,_C_Answer)
	for _, player in ipairs(TableContestants) do ReplicatedStorage:WaitForChild("CheckEvent"):FireClient(player) end
end
local function ResetEventFire(_Q,_Answers,_C_Answer)
	for _, player in ipairs(TableContestants) do ResetEvent:FireClient(player) end
end
Players.PlayerAdded:Connect(function(_player)
	if not table.find(TableContestants,_player) then table.insert(TableContestants,_player) end
end)
local RecievedAnswers = {}
local function NextRound()
	for _, player in ipairs(TableContestants) do
		if not table.find(RecievedAnswers,player) then table.remove(TableContestants,table.find(TableContestants,player)) end
		task.wait() continue
	end
end
local function AddContestants()
	for _, player in ipairs(Players:GetPlayers()) do
		table.insert(TableContestants,player)
	end
end
task.wait(5)
while task.wait() do
	for Rounds = 1, Data.HowManyRoundsAltogether, 1 do
		if not (#Data.Questions >= Rounds) then warn("No Question written, please edit the script and add one") return end
		RoundBegin(Data.Questions[Rounds],Data.TableAnswers[Rounds],Data.TableCorrectAnswers[Rounds])
		local QE = QuestionEvent.OnServerEvent:Connect(function(_player,_correct)
			if _correct then table.insert(RecievedAnswers,_player) else table.remove(TableContestants,table.find(TableContestants,_player)) end
		end)
		task.wait(Data.TimeForEachQuestion)
		CheckEventFire() ResetEventFire() task.wait(1) NextRound()
		task.wait(4)
		QE:Disconnect()
	end
	TableContestants = {}
	AddContestants()
end

image
I the case RoundScript broke, Copy and paste thiz;

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StartEvent = ReplicatedStorage:WaitForChild("StartEvent")
local QuestionEvent = ReplicatedStorage:WaitForChild("QuestionEvent")
local CheckEvent = ReplicatedStorage:WaitForChild("CheckEvent")
local ResetEvent = ReplicatedStorage:WaitForChild("ResetEvent")
local QuestionModule = require(script.Parent:WaitForChild("QuestionModule"))
QuestionEvent.OnClientEvent:Connect(function(_Question,_TableAnswers,_CorrectAnswer,_Time)
	local Correct = QuestionModule.AskQuestion(_TableAnswers,_CorrectAnswer,_Question,_Time)
	if Correct and tick()<=_Time then ReplicatedStorage:WaitForChild("QuestionEvent"):FireServer(Correct) end
	repeat task.wait(1) until tick()>=_Time QuestionModule.FrameScreen(not Correct,4)
end)
ResetEvent.OnClientEvent:Connect(function()
	QuestionModule.Reset()
end)

image

1 Like