Hi, I wanted to ask how I can make a math block race game kinda like this video below.
math.random, raycast, and round system
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
I hope this helped you visualize what you could / wanna do
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()
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?
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.
wait whats the raycast for because i made a game like this and i dont think i used raycast
do you know how i can make a random generated equation?
you think you can help a bit with it?
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.
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
There is no reason you should be raycasting for something that does not need raycasting.
thats the same thing i was wondering.
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