Hello everyone,
Thank you in advance for taking the time to read this.
I am newish to Roblox and I am trying to make a game that displays a random math problem on the screen. Numbers are running around the map and you have to hunt down the answer to the problem and shoot it to get cash. I have almost everything working great, but I have been stuck on this core mechanic for about a week now. I don’t know how to assign the correct answer tag to the correct NPCs so that they award the prize.
I have the script setup to give you $50 for any number you shoot (so I know that is working), but I want it to give you $500 if you shoot the number that is the correct answer.
First I tried to set a bool value to all NPCs and have it changed to true when it was the correct answer while the bots were also named the correct answer, but I don’t know how to recognize the bot to flag it and all it’s respawns.
Then, I came up with an idea to make the key equal to the answer, but that seriously limited my ability to add hundreds of problems and each answer could only have 1 problem, but I couldn’t get even that to work.
Then I tried to setup a matrix by having a table made up of all the answers that were tables to the matching problems, but I got so confused I deleted it all.
Then I tried the approach of using a dictionary for the first time, but I didn’t know how to pull random problems from it and still couldn’t get the bool value to switch. This code has been changed about 30 times so, honestly so I can’t tell you what it does now or if I’m even in the right direction. Please help.
local grade1 = {"0 + 1 = ? ", "1 + 1 = ? ", "0 + 3 = ? ", "2 + 2 = ? ", "2 + 3 = ? "}
--pull a random problem from the table, iterate the loop 5 times
for i = math.random(1,#grade1), 5, -1 do
local v = grade1[i] -- set v to be the math problem and display it to the GUI
status.Value = v
game.Workspace.BaseMap.Bots.i.answer.Value = true -- key is equal to the answer, change bool value to true to grant bonus
wait(20) -- time to solve
game.Workspace.BaseMap.Bots.i.answer.Value = false -- change bool back to false to remove bonus
end
Thank you again for reading and any suggestions in advance.
-Danny
*edit I forgot to include that I have a remote function that triggers the number assigned to a variable and I set up an if statement that checks the bool value of answer to determine which value to assign to amount, but I don’t think there is anything wrong with this code.
*edit I forgot to put the errors. It says in the output that i is not a valid member. I also tried “i”.
*edit here is a link to the game if you would like a visual demonstration. Most things are placeholders or still need detail and the math problems are not active currently to test other game mechanics.