How can I make a math system like this?

hey im having trouble making the plates have random numbers (if that makes sense)

like right now the plates just show as the same random number that i made

Show code please ignore this

ok here

while true do
				local numberA = math.random(0, 10)
				local numberB = math.random(0, 10)

				local answer = numberA + numberB

				QuestionFrame.Visible = ReplicatedStorage:WaitForChild("Values"):WaitForChild("GameStart").Value
				QuestionFrame.Question.Text = numberA.." + "..numberB

				for i = 10, 0, -1 do
					local ConvertT = TFM:Convert(i, "Default", true)

					ReplicatedStorage:WaitForChild("Values"):WaitForChild("QuestionTimer").Value = ConvertT
					task.wait(1)
				end

				for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
					if block.Name == "Number" and block:IsA("BasePart") then
						block.MainUI.Answer.Text = numberA
						block.CanCollide = (tonumber(block.Name) == answer)
					end
				end
			end

this is how the code looks so far

it looks like you’re just setting the text to numberA, which is a fixed value

this conflicts with (tonumber(block.Name) == answer)

fixes:

  1. remove block.Name == "Number"
  2. replace block.MainUI.Answer.Text = numberA to block.MainUI.Answer.Text = math.random(1, 10+10)

hmmm i dont really understand how that would work tho tbh

so is this how its supposed to look?

while true do
				local numberA = math.random(0, 10)
				local numberB = math.random(0, 10)

				local answer = numberA + numberB

				QuestionFrame.Visible = ReplicatedStorage:WaitForChild("Values"):WaitForChild("GameStart").Value
				QuestionFrame.Question.Text = numberA.." + "..numberB
				
				for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
					if block:IsA("BasePart") then
						block.MainUI.Answer.Text = math.random(1, 10+10)
					end
				end

				for i = 10, 0, -1 do
					local ConvertT = TFM:Convert(i, "Default", true)

					ReplicatedStorage:WaitForChild("Values"):WaitForChild("QuestionTimer").Value = ConvertT
					task.wait(1)
				end

				for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
					if block:IsA("BasePart") then
						block.CanCollide = (tonumber(block.Name) == answer)
					end
				end
			end

exactly, did it work?

yes it did thank you. now there is random numbers on all plates. But now, the answer at the top from the random equation if i try and land on the correct answer on the plate. i still fall and die. how do i fix that?

oh i forgot about the name, replace the block.MainUI.Answer.Text with:

local blockNum = math.random(1, 10+10) -- get a random number between 1 to 20

block.MainUI.Answer.Text = blockNum
block.Name = blockNum

oh now they all show the same number for some reason

can you show the updated code?

1 Like

oh wait i managed to fix it. i changed

for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
					if block:IsA("BasePart") then
						block.CanCollide = (tonumber(block.Name) == answer)
					end
				end

to

for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
					if block:IsA("BasePart") then
						block.CanCollide = (tonumber(block.MainUI.Answer.Text) == answer)
					end
				end
1 Like
while true do
	local numberA = math.random(0, 10)
	local numberB = math.random(0, 10)

	local answer = numberA + numberB

	QuestionFrame.Visible = ReplicatedStorage:WaitForChild("Values"):WaitForChild("GameStart").Value
	QuestionFrame.Question.Text = `{numberA} + {numberB}`
	
	for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
		if block:IsA("BasePart") then
			block.MainUI.Answer.Text = math.random(0, 10)
		end
	end

	for i = 10, 0, -1 do
		local ConvertT = TFM:Convert(i, "Default", true)

		ReplicatedStorage:WaitForChild("Values"):WaitForChild("QuestionTimer").Value = ConvertT
		task.wait(1)
	end

	for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
		if block:IsA("BasePart") then
			block.CanCollide = (tonumber(block.MainUI.Answer.Text) == answer)
		end
	end
end

yes now im also having trouble making the plates that arent the right answer completely invisible. and also how would i stop the while true do loop after this wait below?

for i = clonedMap:GetAttribute("TimeEnd"), 0, -1 do
		local ConvertT = TFM:Convert(i, "Default", true)

		ReplicatedStorage:WaitForChild("Values"):WaitForChild("Timer").Value = ConvertT
		task.wait(1)
	end
while true do
	local numberA = math.random(0, 10)
	local numberB = math.random(0, 10)

	local answer = numberA + numberB

	QuestionFrame.Visible = ReplicatedStorage:WaitForChild("Values"):WaitForChild("GameStart").Value
	QuestionFrame.Question.Text = `{numberA} + {numberB}`
	
	for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
		if block:IsA("BasePart") then
			block.MainUI.Answer.Text = math.random(0, 10)
		end
	end

	for i = 10, 0, -1 do
		local ConvertT = TFM:Convert(i, "Default", true)

		ReplicatedStorage:WaitForChild("Values"):WaitForChild("QuestionTimer").Value = ConvertT
		task.wait(1)
	end

	for _, block in clonedMap:WaitForChild("Plates"):GetChildren() do
		if block:IsA("BasePart") then
            local isCorrectBlock = (tonumber(block.MainUI.Answer.Text) == answer)
			block.CanCollide = isCorrectBlock
            block.Transparency = isCorrectBlock and 0 or 1
		end
	end
end

Huh?

wait so it works but how do i fix these numbers still showing

image

(And i need it after a certain amount of time for the plates to go back to normal with another random generated equation and answer/numbers)

and what i mean by stopping the while true do loop is the one i created for this whole thing to work. but i want it to completly stop after the game ends which is controlled right here ig

for i = clonedMap:GetAttribute("TimeEnd"), 0, -1 do
		local ConvertT = TFM:Convert(i, "Default", true)

		ReplicatedStorage:WaitForChild("Values"):WaitForChild("Timer").Value = ConvertT
		task.wait(1)
	end

(if this all makes sense still)

So tried doing the math to generate a random equation for either a addition, or subtraction question to match the number given:

local max = 10
local min = -10
-- set these numbers to your liking

local function eq(x: number?)
	x = x and math.clamp(x, min, max) or math.random(min, max)
    -- if x exists, then it will be a value within the range of
    -- min, and max, otherwise it will pick a number number within
    -- that range
	
	local ax = math.abs(x) -- to make sure the number is positive
    -- this is to avoid errors
    
	local x1 = x - math.random(-ax, ax) -- subtract x with a random number
	local x2 = x - x1 -- find the other half of the equation
	
	local eqType = if x1 < x2 and x2 < x1 then "-" else "+"
    -- this is to diagnose whether the equation should be addition
    -- or subtraction
    
	return x, `{x1} {eqType} {x2}` -- returns both the number and 
    -- equation for use
end

for i = 1,10 do -- runs 10 times
    print(eq()) -- test print (will pick random numbers)
end

Let me know if something is wrong, because I went through hours of Trail and Error to figure out how to format it correctly

1 Like
  • never, EVER use ChatGPT to learn. GPT-3 will literally make up fake events and methods. Not sure about GPT-4.
  • Elaborate on coaching. Do you mean tutors? They can cost quite a lot, I wouldn’t recommend it.
  • I would personally look at a few tutorials on certain topics.
  • I already had quite a good background in programming so it wasn’t that hard for me to grasp Lua. Also, I would advise roaming the DevForum in general to find solutions to your problems and finding generally useful coding practices. Sometimes, the best way to solve your own problems is to help someone else.
  • Dissect and pull apart some open-source code from high-rated models in the Toolbox. This is how I learned pretty quickly.
1 Like