Roblox U game loop, help?
001 | local checkpoint 1 = game.Workspace.Checkpoint 1 |
002 | local checkpoint 2 = game.Workspace.Checkpoint 2 |
003 | local checkpoint 3 = game.Workspace.Checkpoint 3 |
005 | local oldcars = game.ServerStorage:GetChildren() |
007 | local raceInProgress = false |
009 | function showVictoryMessage(playerName) |
010 | if show = = false then |
012 | local message = Instance.new( "Message" ) |
013 | message.Text = playerName .. " wins!" |
014 | message.Parent = game.Workspace |
022 | function destroyCars() |
023 | if raceInProgress = = true then |
024 | for _, object in pairs (game.Workspace:GetChildren()) do |
026 | if object.Name = = "Car" then |
027 | print ( "This is a car, we need to destroy it!" ) |
035 | for _, object in pairs (game.ServerStorage:GetChildren()) do |
036 | local oldcar = object:Clone() |
037 | oldcar.Parent = game.Workspace |
043 | function CreateCarsV 2 () |
044 | for _, object in pairs (game.ServerStorage:GetChildren()) do |
045 | local carClone = object:Clone() |
046 | if carClone and carClone.Parent = = game.ServerStorage then |
047 | carClone.Parent = game.Workspace |
048 | carClone:MakeJoints() |
053 | function checkpoint 1 hit(otherPart) |
054 | print ( "Checkpoint1 was hit!" ) |
055 | print (otherPart.Name) |
056 | if otherPart ~ = nil and otherPart.Parent ~ = nil and otherPart.Parent:FindFirstChild( "Humanoid" ) then |
057 | print ( "A player hit me!" ) |
058 | if not checkpoint 1 :FindFirstChild(otherPart.Parent.Name) then |
059 | local playerTag = Instance.new( "StringValue" ) |
060 | playerTag.Parent = checkpoint 1 |
061 | playerTag.Name = otherPart.Parent.Name |
062 | playerTag.Value = otherPart.Parent.Name |
065 | if checkpoint 3 :FindFirstChild(otherPart.Parent.Name) and raceInProgress = = true then |
068 | showVictoryMessage(otherPart.Parent.Name) |
069 | raceInProgress = false |
075 | function checkpoint 2 hit(otherPart) |
076 | print ( "Checkpoint2 was hit!" ) |
077 | print (otherPart.Name) |
078 | if otherPart ~ = nil and otherPart.Parent ~ = nil and otherPart.Parent:FindFirstChild( "Humanoid" ) then |
079 | print ( "A player hit me!" ) |
080 | if not checkpoint 2 :FindFirstChild(otherPart.Parent.Name) and checkpoint 1 :FindFirstChild(otherPart.Parent.Name) then |
081 | local playerTag = Instance.new( "StringValue" ) |
082 | playerTag.Parent = checkpoint 2 |
083 | playerTag.Name = otherPart.Parent.Name |
084 | playerTag.Value = otherPart.Parent.Name |
089 | function checkpoint 3 hit(otherPart) |
090 | print ( "Checkpoint1 was hit!" ) |
091 | print (otherPart.Name) |
092 | if otherPart ~ = nil and otherPart.Parent ~ = nil and otherPart.Parent:FindFirstChild( "Humanoid" ) then |
093 | print ( "A player hit me!" ) |
094 | if not checkpoint 3 :FindFirstChild(otherPart.Parent.Name) and checkpoint 2 :FindFirstChild(otherPart.Parent.Name) then |
095 | local playerTag = Instance.new( "StringValue" ) |
096 | playerTag.Parent = checkpoint 3 |
097 | playerTag.Name = otherPart.Parent.Name |
098 | playerTag.Value = otherPart.Parent.Name |
103 | checkpoint 1. Touched:connect(checkpoint 1 hit) |
104 | checkpoint 2. Touched:connect(checkpoint 2 hit) |
105 | checkpoint 3. Touched:connect(checkpoint 3 hit) |
108 | local redLight = game.Workspace.StartLight.RedModel.LightBulb.PointLight |
109 | local yellowLight = game.Workspace.StartLight.YellowModel.LightBulb.PointLight |
110 | local greenLight = game.Workspace.StartLight.GreenModel.LightBulb.PointLight |
111 | local startBarrier = game.Workspace.StartBarrier |
113 | function startLightCycle() |
116 | redLight.Enabled = true |
120 | redLight.Enabled = false |
121 | yellowLight.Enabled = true |
125 | yellowLight.Enabled = false |
126 | greenLight.Enabled = true |
129 | function removeBarrier() |
130 | startBarrier.Transparency = 1 |
131 | startBarrier.CanCollide = false |
134 | function resetLights() |
135 | redLight.Enabled = false |
136 | yellowLight.Enabled = false |
137 | greenLight.Enabled = false |
140 | function resetBarrier() |
141 | startBarrier.Transparency = 0.5 |
142 | startBarrier.CanCollide = true |
145 | function clearCheckpoint(checkpoint) |
146 | for _, object in pairs (checkpoint:GetChildren()) do |
147 | if object.Name ~ = "TouchInterest" then |
169 | clearCheckpoint(checkpoint 1 ) |
170 | clearCheckpoint(checkpoint 2 ) |
171 | clearCheckpoint(checkpoint 3 ) |
179 | raceInProgress = false |
181 | while raceInProgress = = true do |
I watched the video and I copied the code character to character but it before the race is over, it will start the game loop from the beginning. It would make new cars and delete cars while the race is still in progress.