I am working on fixing a quiz that I want images to display on for every question. However, images do not show for a reason I am not sure how to fix.
I’ve tried getting the asset ID but have failed. I replaced the images I used before with a placeholder image.
Beforehand, the images would error out but I can no longer find the error.
local Players = game:GetService("Players")
local StS = game:GetService("StarterGui")
local ReS = game:GetService("ReplicatedStorage")
local CoP = game:GetService("ContentProvider")
local localPlayer = Players.LocalPlayer
local Images = {
"rbxassetid://6916522793",
"rbxassetid://6916522793",
"rbxassetid://6916522793",
"rbxassetid://6916522793",
"rbxassetid://6916522793"
}
--CoP:PreloadAsync(Images)
local Questions = {
{Question = "Placeholder1",Answer = true, Response = nil, Images[1]},
{Question = "Placeholder2",Answer = true, Response = nil, Image = Images[2]},
{Question = "Placeholder3",Answer = true ,Response = nil, Image = Images[3]},
{Question = "Placeholder4",Answer = false,Response = nil,Image = Images[4]},
{Question = "Placeholder5",Answer = false,Response = nil,Image = Images[5]},
--{Question = "",Answer = false,Response=nil,Image = nil}
}
local CurrentQuestion = 1
local IsInTest = false
local TestPaper = workspace.Test
local Background = script.Parent
local QuestionText = Background.Question
local QuestionNumber = Background.QuestionNumber
local Image = Background.Image
function RandomizeTable(x1,x2)
if x1.Question:len() > x2.Question:len() then
return true
end
return false
end
function DrawQuestion() -- getting question data and writing to screen
local cQuestion = Questions[CurrentQuestion]
QuestionText.Text = cQuestion.Question
QuestionNumber.Text = "Question " .. CurrentQuestion .. "/" .. #Questions
if not cQuestion.Image then
Image.Visible = false
else
Image.Visible = true
Image.Image = cQuestion.Image
end
end
function CheckResponseAnswer() -- to be ran at the end of the test
local numCorrect = 0
for i,question in pairs(Questions) do
if question.Answer == question.Response then
numCorrect = numCorrect + 1
end
end
local percent = (numCorrect/#Questions)*100
local punctation = percent == 100 and "! (Amazing)" or (percent > 0 and percent < 100) and ". (Mediocre)" or ". (Pathetic)"
QuestionText.Text = "You are " .. percent .. "%" .. punctation
QuestionNumber.Text = "Results"
if percent == 100 then
workspace.Decoration.SecretPoster:Destroy()
end
Background.YesButton.Visible = false
Background.NoButton.Visible = false
wait(2.5)
ReS.DidTest.Value = true
IsInTest = false
Background.Visible = false
end
function IncrementCurrentQuestion() -- runs when question is answered
if IsInTest then
CurrentQuestion = CurrentQuestion + 1
if CurrentQuestion > #Questions then
CurrentQuestion = 1
IsInTest = false
CheckResponseAnswer()
else
DrawQuestion()
end
end
end
Background.YesButton.MouseButton1Click:Connect(function()
if IsInTest then
Questions[CurrentQuestion].Response = true
IncrementCurrentQuestion()
end
end)
Background.NoButton.MouseButton1Click:Connect(function()
if IsInTest then
Questions[CurrentQuestion].Response = false
IncrementCurrentQuestion()
end
end)
TestPaper.ClickDetector.MouseClick:Connect(function(player)
if player == localPlayer and not ReS.DidTest.Value then
table.sort(Questions,RandomizeTable)
DrawQuestion()
IsInTest = true
Background.Visible = true
Background.YesButton.Visible = true
Background.NoButton.Visible = true
end
end)