How would I make a game like this?

Hi, I wanted to ask how I can make a math block race game kinda like this video below.

7 Likes

math.random, raycast, and round system

3 Likes

To extend on what @lV0rd said, you could do something similar to this OP
[@NotPerplexedlul]:

function chooseNumber()
     return math.random(1, 10)
end

function Start()
   local num = chooseNumber()
   local Ray = workspace:Raycast(HumanoidRootPart.Position, -HumanoidRootPart.CFrame.UpVector)
   if Ray then
   if Ray.Instance:IsA(“Part”) and Ray.Instance.SurfaceGui.TextLabel.Text == num then
for i, v in pairs(workspace.Whereeveryourpartsare:GetChildren()) do
   if v.SurfaceGui.TextLabel.Text ~= Ray.Instance.SurfaceGui.TextLabel.Text then
   v.Transparency = 1
   v.CanCollide = false
   end
end
task.wait(idk_youchoose)
for i, v in pairs(workspace.Whereeveryourpartsare:GetChildren()) do
   v.Transparency = 0
   v.CanCollide = true
          end
      end
   end
end

task.spawn(function()
   while task.wait(round_time) do
         Start()
     end
end)

THIS ISNT THE MOST EFFICIENT WAY

Note

Please correct me if I made any sort of mistakes

Also I manually indented the lines on mobile :laughing:

I hope this helped you visualize what you could / wanna do :slight_smile:

P.S. For the in pairs loops I added some random stuff so if your parts are gonna be stored in workspace just change both of them to workspace:GetChildren()

4 Likes

thank you. and sorry for the late reply. i will try this out right now

hm idk why but it doesnt work. Also how do i make the equation at the top? (like a random generated equation) and they have to step on the right answer if that make sense.

how would i make the equation at the top tho?

you could generate an answer by adding or subtracting two random generated numbers (which you could tweak accordingly in order to get a range of numbers you could generate), and then you could just display the two numbers and operation in a gui on the top of the screen.

do you think you can give a quick code snippet of how that would look like? (I kinda understand)

how would i make the equation at the top tho?

On-Screen UI Containers

Probably using a screen GUI, frame and label, possibly an image thrown in for the background. You can update that using a local script.

You’ll probably want to put that inside of the PlayerGui

Updating the label is simple enough, something like this:

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
playerGui.frameName.labelName.Text = "1+1" 

or whatever.

2 Likes

wait whats the raycast for because i made a game like this and i dont think i used raycast

1 Like

do you know how i can make a random generated equation?

1 Like

you think you can help a bit with it?

1 Like

The game in the video only has possible answers up to 10. Assuming you want to copy that mechanic:

First, generate a random number from either 0 or 1 (if you’re including 0 or not) to 10.
Generate a second number in the range of 0/1 to (10-yourFirstNumber).

It seems like almost everyone has made a copy of this game at some point. I started off with something like the one in the video but I changed the mechanics enough that hardly resembles the original idea. It gets boring pretty fast play-testing basic addition races against yourself.

4 Likes

Shoot a raycast down from the root part of the character, get the result and check if the result is the correct block… It’s a better way than using Touched event or region3

1 Like

There is no reason you should be raycasting for something that does not need raycasting.

3 Likes

thats the same thing i was wondering.

2 Likes

you could just store an attribute in each block that holds a random number then just delete all the ones that aren’t equal to the answer. there isn’t any real reason to use raycasts for something like this

3 Likes