How to make a Time Trial Game! [PART 1 - 15 Minutes]

Overview :orange_book:

Hello, in this tutorial I will be teaching you the basics of making a Time-Trial Game, Time-Trial Games are basically obby games with a speedrunning aspect added to them, the goal is to finish an obby in the fastest time possible, so we will replicate that today. Here are some examples of Time-Trial games that have been popularized, the RBXL of today’s tutorial, and all of the Roblox API links you can click on to learn more about the topic:

Time Trial Game Examples

- Time Tactic
- Amir’s Time Trial
- Time Test
- Test Your Time!

RBXL File

TimeTrialPart1.rbxl (34.0 KB)

Roblox API's Of Things You Should Study

The Setup :gear:

Step 1: Make a simple obby with a START and END block in studio (obviously it can be more detailed but for this tutorial, it won’t be)

Step 2:
Name your Start/End blocks, and organize everything into a folder:

image

Step 3:
We’re gonna add a ScreenGui in StarterGui, then a frame in it, and a text label in that frame, then add a “UI Corner” into the TextLabel and Frame, and color them however you like, remember to go into the properties of your text, change the font if you want and check the bool “TextScaled” for a better look it should look a little like this once you finish those steps:

Step 4:
Add a script into the Start and End parts, then a Local-Script into the TextLabel Gui and a script into ServerScriptService, with a BoolValue inside of the script, then another script in ServerScriptService:

image

image

The Scripting :desktop_computer:

Alright, we’re gonna get into the fun part, scripting!
In this tutorial, we won’t be doing that much, but in the next couple of tutorials more will come:

In the start script, we need this, it sets the Bool to true when you step on it:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		local BoolVal = Player:WaitForChild("BoolStartEnd")
		
		BoolVal.Value = true
	end
end)

In the end script, we need this, it sets the Bool to false when you step on it:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		local BoolVal = Player:WaitForChild("BoolStartEnd")

		BoolVal.Value = false
	end
end)

Next, in our “BoolDiedScript”, in ServerScriptService we need to make the timer end once you die (or it would be really weird):

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function(died)
			local Bool = player:WaitForChild("BoolStartEnd")
			local TimerText = player:WaitForChild("PlayerGui").TimerGui.Frame.Timer
			Bool.Value = false
			TimerText.TextColor3 = Color3.fromRGB(255, 0, 4)
			
			player:Connect(function()
				TimerText.TextColor3 = Color3.fromRGB(50, 50, 50)
			end)
		end)
	end)
end)

In our local-script under timer-text were gonna have this, this is the actual script for the timer, it will be modified in future tutorials:

local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")

local Timer = PlayerGui:WaitForChild("TimerGui").Frame.Timer
local BoolVal = game:GetService("Players").LocalPlayer:WaitForChild("BoolStartEnd")
local Time = 0

while wait() do
	if BoolVal.Value == true then
		Timer.TextColor3 = Color3.fromRGB(50,50,50)
		Timer.Visible = true
		Timer.Text = Time.."s"
		wait(0.1)
		Time = Time + 0.1
	elseif BoolVal.Value == false then
		Timer.TextColor3 = Color3.fromRGB(0, 255, 0)
		Time = 0
	end
end

In the BoolValue-Script under ServerScriptService (the one with a bool inside it) were gonna have this script that basically clones that BoolValue INTO the player:

game:GetService("Players").PlayerAdded:Connect(function(player)
	script:WaitForChild("BoolStartEnd"):Clone().Parent = player
end)

Final Result

Here’s how it all came out, not the best because this is just part 1, but I will make lots more parts hopefully

The End :wave:

Although this is a very simple script and definitely needs improvement, it should be a starting place for this series.

This was my second tutorial, rate it on a scale of 1/10 please!
  • 1 :poop:
  • 2 :face_vomiting:
  • 3 :yawning_face:
  • 4 :confused:
  • 5 :neutral_face:
  • 6 :slightly_smiling_face:
  • 7 :ok_hand:
  • 8 :+1:
  • 9 :smiley:
  • 10 :star_struck:

0 voters

7 Likes

the way you’ve set the game up overall just isn’t efficient as your end/start scripts won’t be coordinated with eachother and can possibly cause a lot of issues in the long road.

also for your characteradded function I recommend using waitforchild for the humanoid instead just to prevent any possible errors.

also howcome you don’t just use fireclient on a remote and handle the UI via the client, this cuts out the possible errors of the UI not being found and breaking the death system as well.

also since when can you connect to the player? i don’t ever recall having knowledge of player:Connect??

for the touched handler I recommend checking if the Player value is nil or not to prevent more code errors.

obviously this post is the basic (really the most basic) explanation on how to make a time trial game but most to make a good time trial game you’d need a good anticheat, fault-proof detection (touched isn’t always the best option), etcetera.

i rate this tutorial a 4.5/10 if this is a full guide to making a proper time trial game and a 5.5/10 if this is a guide to make a basic time trial game due to there not being proper explanation on any of the functions meaning you cannot learn how to make a time trial game from scratch.

edit : just noticed you haven’t even checked if the trial has started yet meaning if you coordinated the endings with a leaderboard, you’d have tons of exploiters.

4 Likes

Sorry I’m not an amazing scripter, Im just trying to do a basic thing

1 Like

You should add comments to ur scripts

2 Likes

Amazing! Although I am a advanced scripter, this would be super useful for new developers to learn the basics of scripting!

You should try a main menu system on the next tutorial with upgrades!

1 Like