NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

---------------------------
---variable declarations---
---------------------------
math.randomseed(tick());--sets randomseed so the game selection is more random
local poolDepth=3;--depth of water
local poolLength=82;--length of water
local laneWidth=5;--length of one lane
local laneCount=6;--number of lanes
local xMax=math.ceil((poolLength)/2);--the length of half the pool on the x
local zMax=math.ceil((laneCount*laneWidth+(laneCount-1))/2);--the length of half the pool on the z
local laneTeles=workspace.LaneTeles;--because I'm lazy, I made lane teleport bricks instead of using a bunch of math :P
local laps=0;--number of laps the race will be. 1-5
local held=workspace.held;--hint for displaying text
local startTime=0;--tick() that the race started at
local foundWinner=false;--says if someone has already one or not
local leftRacing=0;--how many people are still going
local displays=workspace.Displays;--the big green and blue things. Used for distance and telling where to go
local Racin=workspace.Racin;--says whether the race is happening or not
local Blocker=workspace.Blocker;--this block blocks the racers from false starting
_G.lineup={};--the people in the race. For leaderboard

---------------------------
---function declarations---
---------------------------

--teleports a humanoid to a specific lane
function teleport(character,lane)
local b=pcall(function() character.Humanoid.WalkSpeed=0; end);
if b then
return pcall(function() character.Torso.CFrame=laneTeles["L"..tostring(lane)].CFrame; end);
else
return false;
end end

--sends a message to all the players in the game
function message(msg,dur)
for _,v in pairs(game.Players:GetChildren()) do
v.PlayerGui.disp.msg.Text=msg;
end
Wait(dur or 3);
for _,v in pairs(game.Players:GetChildren()) do
v.PlayerGui.disp.msg.Text="";
end
end

--checks if the player is staying away from going under, or over, the rope. Returns true if they are on the ropes
function InBounds(character)
if character and character:findFirstChild("Torso") then
if workspace.Terrain:WorldToCellPreferSolid(character.Torso.Position).z%(laneWidth+1)==0 then
return false;
end end
return true;
end

--checks for lap change. Returns true if they are done
function endOfLap(playa)
if playa.Character and playa.Character:findFirstChild("Torso") then--checks for the player
local spot=workspace.Terrain:WorldToCellPreferSolid(playa.Character.Torso.Position).x;
if spot<=-xMax+1 and playa.isGoing.Value and playa.racing.Value then--if they hit the far wall
playa.isGoing.Value=false;
elseif spot>=xMax-1 and not playa.isGoing.Value and playa.racing.Value then--if they hit the close wall
playa.isGoing.Value=true;
playa.leaderstats.Lap.Value=playa.leaderstats.Lap.Value+1;
if playa.leaderstats.Lap.Value>=laps and not foundWinner then
return true;
end end end
return false;
end

--gives a pretty display of time passed. Takes in seconds.
function timer(seconds)
local milliseconds=seconds%1;--gets the decimal from the number
local seconds=seconds-milliseconds;--whole number seconds
return math.floor(seconds/60)..--minutes
(seconds%60>=10 and ":" or ":0")..tostring(seconds%60)..--seconds
":"..("%0.3f"):format(milliseconds):sub(3);--milliseconds
end

--Sort the table tab in place
function selection_sort(tab)
--Go through every position in the table
for i = 1, #tab do
--start minimum at current position
local minimum = i
--Go through the remaining elements that need to be sorted
for t = i + 1, #tab do
--compare current element to minimum
if tab[t].pos < tab[minimum].pos then
--t is the new minimum
minimum = t
end
end
--switch minimum with current position
tab[i], tab[minimum] = tab[minimum], tab[i]
end
end

--runs a race
function Race()
laps=math.random(5);
Blocker.CanCollide=true;
Racin.Value=true;
--teleports players and gets them set to race
for i,v in pairs(game.Players:GetChildren()) do
if not v.DataReady then
v:WaitForDataReady();
end
v.leaderstats.Wins.Value=v:LoadNumber("qwertyWASKL");
if i<=6 and teleport(v.Character,i) then
v.isGoing.Value=true;
v.racing.Value=true;
v.leaderstats.Lap.Value=0;
end end
--countdown
held.Text=laps.." lap race. 1 lap=down and back. It will not count if you turn around before your GUI changes colors.";
for i=5,1,-1 do
message(i,1);
end
Spawn(function() message("GO!"); end);
Blocker.CanCollide=false;
for _,v in pairs(game.Players:GetChildren()) do
pcall(function() v.Character.Humanoid.WalkSpeed=workspace.Speed.Value; end);
end
startTime=tick();
--repeat until winner is found
foundWinner=false;
leftRacing=0;
repeat
Wait(0.1);
local temp={};
local leftRacing=0;
held.Text=laps.." lap race. Timer : "..timer(tick()-startTime);
for _,v in pairs(game.Players:GetChildren()) do
if v.racing.Value then
pcall(function() table.insert(temp,{--inserts into table
['player']=v;--racer
['pos']=(-1)*(v.leaderstats.Lap.Value*10000+--10000 points per lap
(v.isGoing.Value and 0 or 5000)+--5000 if already turned around
math.abs(v.Character.Torso.Position.X-(v.isGoing.Value and displays.G or displays.B).Position.X));--distance
}); end);
leftRacing=leftRacing+1;
if not InBounds(v.Character) then
v.isGoing.Value=false;
v.racing.Value=false;
v.leaderstats.Lap.Value=0;
pcall(function() v:LoadCharacter(); end);
elseif endOfLap(v) then
foundWinner=true;
message(v.Name.." has won the race!");
if not v.DataReady then
v:WaitForDataReady();
end
v:SaveNumber("qwertyWASKL",v:LoadNumber("qwertyWASKL")+1);--wins protected from hackers
v.leaderstats.Wins.Value=v:LoadNumber("qwertyWASKL");
end end end
selection_sort(temp);
_G.lineup=temp;
until foundWinner or leftRacing==0
--reset everything
Racin.Value=false;
for _,v in pairs(game.Players:GetChildren()) do
if v.racing.Value then pcall(function() v:LoadCharacter() end);
end end
end

--------------
---Run Code---
--------------

while Wait(4) do
--check for enough players
while #game.Players:GetChildren()<2 do
held.Text="Two or more players needed to start";
Wait(0.2);
end
--countdown
for i=60,0,-1 do
Wait(1);
held.Text=timer(i);
if #game.Players:GetChildren()<2 then
break;--ends countdown if not enough players
end end
--begin race if enough players. After the if it will go back to the top and start again
if not (#game.Players:GetChildren()<2) then
Race();
end end
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.