If then not working

I am making a personality test game for fun, but the if then statement is not working, here is the code:

Questions = {
		"You're walking with your friends but one of them needs to tie their shoelaces, what will you do?",
		"You're over at your friends house, and their parents offer you snacks. How will you respond?",
		"Aww, man! It's the first day of school! How do you plan to dress?"
	}
	Answers = {
		{
			"Leave him behind and keep walking with my friends",
			"Get mad at him",
			"Get my friends to wait for him with me",
			"Stay and wait for him to finish",
		},
		{
			"Ignore them and keep talking with your friends.",
			"Rudely take the snacks and eat them",
			"Thank them but deny the snacks",
			"Respectfully accept the kind offer"
		},
		{
			"I'll be rockin that Punk look!",
			"Minimalistic, only a tank top and shorts.",
			"Trying my best to look cute!",
			"Gotta Dress Casual"
		}
	}

	--[Determining the Typing of the Destined Pokemon]
	RandomQuestion = math.random(1.0,3.0)
	local Prompts1 = Answers[Dialogue:PromptMultipleChoice(Questions[RandomQuestion], Answers[RandomQuestion], true)]
	Points = {
		Hardy = 0.0,
		Docile = 0.0,
		Brave = 0.0,
		Jolly = 0.0,
		Impish = 0.0,
		Naive = 0.0,
		Timid = 0.0,
		Hasty = 0.0,
		Sassy = 0.0,
		Calm	 = 0.0,
		Relaxed = 0.0,
		Lonely = 0.0
	}
	
	local function AddPoints(Nature, NewPoints)
		print(Nature, NewPoints)
		Points[Nature] = Points[Nature] + NewPoints
	end

	if Prompts1 == "Leave him behind and keep walking with my friends" then
		table.insert(Personality, "You're not the best friend, but you're funny.")
		AddPoints("Hardy", 1.0)
	elseif Prompts1 == "Get mad at him" then
		table.insert(Personality, "You've got a short temper, but you know how to get stuff done.")
		AddPoints("Docile", 1.0)
	elseif Prompts1 == "Get my friends to wait for him with me" then
		table.insert(Personality, "You're a great friend, all in all you really care for others.")
		AddPoints("Brave", 1.0)
	elseif Prompts1 == "Stay and wait for him to finish" then
		table.insert(Personality, "You're a loyal friend, always ready to help out.")
		AddPoints("Jolly", 1.0)

	elseif Prompts1 == "Ignore them and keep talking with your friends." then
		table.insert(Personality, "You like to focus on one thing until you are finished before moving on with the next.")
		AddPoints("Hardy", 1.0)
	elseif Prompts1 == "Rudely take the snacks and eat them" then
		table.insert(Personality, "You're very opportunistic. Ready to take chances while they are there.")
		AddPoints("Docile", 1.0)
	elseif Prompts1 == "Thank them but deny the snacks" then
		table.insert(Personality, "You're very humble. Valuing others before yourself.")
		AddPoints("Brave", 1.0)
	elseif Prompts1 == "Respectfully accept the kind offer" then
		table.insert(Personality, "You are very kind, but opportunistic. Not willing to deny something when it is offered to you.")
		AddPoints("Jolly", 1.0)
		
	elseif Prompts1 == "I'll be rockin that Punk look!" then
		table.insert(Personality, "You love to express your interests, it's a very fun look!")
		AddPoints("Hardy", 1.0)
	elseif Prompts1 == "Minimalistic, only a tank top and shorts." then
		table.insert(Personality, "You don't need much to be happy.")
		AddPoints("Docile", 1.0)
	elseif Prompts1 == "Trying my best to look cute!" then
		table.insert(Personality, "You like it when people compliment you and like you.")
		AddPoints("Brave", 1.0)
	elseif Prompts1 == "Gotta Dress Casual" then
		table.insert(Personality, "You don't mind blending in, sometimes socializing isn't the best.")
		AddPoints("Jolly", 1.0)
	end

It does not error at all, it just does not run the code in the statements.

1 Like

Print out what Prompts1 is exactly, it might not be what you think it is.

Is the script enabled, that may be why.

Oh, it returns nil. Is there anything wrong with the code?

local Prompts1 = Answers[Dialogue:PromptMultipleChoice(Questions[RandomQuestion], Answers[RandomQuestion], true)]

This line in your code is a little confusing, you should break it down into variables that you can print out to see if you are getting the expected results.

It all looks correct to me, and the multiple choice utility is not broken.

NEVERMIND! I FIGURED THIS OUT!
I had to change

Answers[Dialogue:PromptMultipleChoice(Questions[RandomQuestion], Answers[RandomQuestion], true)]

to

Dialogue:PromptMultipleChoice(Questions[RandomQuestion], Answers[RandomQuestion], true)

My point is that you shouldn’t have lines of code like that though, you should define more variables to make it easier to debug in the future.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.