Hello, I am currently using a tutorial to learn to script and I tried to create my own version of the code I found on the tutorial, but it doesn’t work.
local startLine = game.Workspace.RaceParts.Start
local finishLine = game.Workspace.RaceParts.Finish
local raceActive = false
local raceTime = 0
print ("Variable are Set")
local function startRace(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid and raceActive == false then
print ("Human touched start")
raceActive = true
print ("Race has started")
end
end
local function mainRace()
print ("You finished the race: "..raceTime)
if raceTime <= 10 then
print ("Race time was less than 10 seconds")
print ("Excellent")
elseif raceTime > 10 and raceTime <= 20 then
print ("Race time was less than 20 seconds")
print ("Not bad")
elseif raceTime > 20 and raceTime <= 30 then
print ("Race time was less than 30 seconds")
print ("Poor")
else
print ("You have basically failed")
print ("Worst perfomance ever")
end
end
local function endRace(otherPartTwo)
local charactera = otherPartTwo.Parent
local humanoida = charactera:FindFirstChildWhichIsA("Humanoid")
if humanoida and raceActive == true then
raceActive = false
print ("Humanoid has touched end, calulating scores...")
mainRace()
end
end
startLine.Touched:Connect(startRace)
finishLine.Touched:Connect(endRace)
if raceActive == true then
print ("The race is on")
end
while raceActive == true do
wait(1)
raceTime = raceTime + 1
print (raceTime)
end
As you can see I tried to use print debugging to find out the part of the code that doesn’t work and here is what I got in the output window:
apparently, this part of the code just doesn’t run and I don’t know why.
if raceActive == true then
print ("The race is on")
end
while raceActive == true do
wait(1)
raceTime = raceTime + 1
print (raceTime)
end
thank you.