of     2   
chevron_rightchevron_rightchevron_right

MichaelRaptor
#223892202Friday, August 18, 2017 11:25 PM GMT

I'm creating a racing game. I want it to only start the race when there are at least 2 people in the game. I coded it. And when I test it with 2 people it doesn't start the race. I even tried changing the code so only 1 person is required, and it still didn't work. Can someone please help me? here's my code for it. local MinimumPlayers = 2 while true do --wait for enough players before we start the game while game.Players.Numplayers < MinimumPlayers do wait() end
BunnyBoy26
#223892262Friday, August 18, 2017 11:27 PM GMT

I hope this isn't the whole script.
MichaelRaptor
#223892304Friday, August 18, 2017 11:28 PM GMT

It's not the whole script for the game. I'll post the whole game's script if neccasery
KEVEKEV77
#223892305Friday, August 18, 2017 11:28 PM GMT

You have to add the code that starts the game.....
MichaelRaptor
#223892362Friday, August 18, 2017 11:29 PM GMT

local Checkpoint1 = game.works##########################################################################################################################lo#####e######## game.workspace.StartLight.Red.PointLight local Yellowlight = game.workspace.StartLight.Yellow.PointLight local Greenlight = game.workspace.StartLight.Green.PointLight local StartBarrier = game.workspace.StartBarrier local lobbySpawn = game.workspace.LobbySpawn local TrackSpawn = game.workspace.TrackSpawn local MinimumPlayers = 2 function Respawncars() print("I am going to respawn the cars now") for _, object in pairs(game.ServerStorage:GetChildren()) do local carCopy = object:Clone() carCopy.Parent = game.workspace carCopy:MakeJoints() end end local RaceInProgress = false function DestroyCars() for _, object in pairs(game.Workspace:GetChildren()) do print(object.name) if object.name == "Car" then print("This is a car! We must exterminate!") object:Destroy() end end end function CreateCars() for _, object in pairs(game.ServerStorage:GetChildren()) do local carCopy = object:Clone() carCopy.Parent = game.workspace carCopy:MakeJoints() end end function ShowVictoryMessage(PlayerName) local message = Instance.new("Message") message.Text = PlayerName .. " Has won!" message.Parent = game.Workspace wait(2) message:Destroy() end function checkpoint1hit(otherPart) print("Checkpoint 1 was hit") print(otherPart.name) if otherPart ~= nil and otherPart.Parent ~= nil and otherPart.parent:FindFirstChild("Humanoid") then print("a player hit me") if not Checkpoint1:FindFirstChild(otherPart.Parent.Name) then local playerTag = Instance.new("StringValue") playerTag.Parent = Checkpoint1 playerTag.Name = otherPart.Parent.Name end if Checkpoint3:FindFirstChild(otherPart.Parent.Name)and RaceInProgress then print("Player wins!") RaceInProgress = false ShowVictoryMessage(otherPart.Parent.Name) end end end function checkpoint2hit(otherPart) print("Checkpoint 2 was hit") print(otherPart.name) if otherPart ~= nil and otherPart.Parent ~= nil and otherPart.parent:FindFirstChild("Humanoid") then print("a player hit me") if not Checkpoint2:FindFirstChild(otherPart.Parent.Name) and Checkpoint1:FindFirstChild(otherPart.Parent.Name) then local playerTag = Instance.new("StringValue") playerTag.Parent = Checkpoint2 playerTag.Name = otherPart.Parent.Name end end end function checkpoint3hit(otherPart) print("Checkpoint 3 was hit") print(otherPart.name) if otherPart ~= nil and otherPart.Parent ~= nil and otherPart.parent:FindFirstChild("Humanoid") then print("a player hit me") if not Checkpoint3:FindFirstChild(otherPart.Parent.Name) and Checkpoint2:FindFirstChild(otherPart.Parent.Name) then local playerTag = Instance.new("StringValue") playerTag.Parent = Checkpoint3 playerTag.Name = otherPart.Parent.Name end end end Checkpoint1.touched:connect(checkpoint1hit) Checkpoint2.touched:connect(checkpoint2hit) Checkpoint3.touched:connect(checkpoint3hit) function StartLightCycle() wa####### #e################ true wa####### #e################ false Yellowlight.Enabled = true wait(1) Yellowlight.Enabled = false Greenlight.Enabled = true end function removeBarrier() StartBarrier.Transparency = 1 StartBarrier.CanCollide = false end function ResetLights() Redlight.Enabled = false Yellowlight.Enabled = false Greenlight.Enabled = false end function ResetBarrier() StartBarrier.Transparency = 0.5 StartBarrier.CanCollide = true end function ClearCheckpoint(checkpoint) for _, object in pairs(checkpoint:GetChildren()) do if object.Name ~= "TouchInterest" then object:Destroy() end end end function Cl################## for _, object in pairs(Checkpoint1:GetChildren()) do if object.Name ~= "TouchInterest" then object:Destroy() end end end function teleportPlayers(target) for _, player in pairs(game.Players:GetChildren()) do local character = player.Character local torso = character.HumanoidRootPart torso.CFrame = target.CFrame end end wait(10) while true do --wait for enough players before we start the game while game.Players.Numplayers < MinimumPlayers do wait() end -- setup racetrack -- turn off all lights ResetLights() -- reset barrier ResetBarrier() -- teleport players to Race teleportPlayers(game.Workspace.TrackSpawn) -- create more cars CreateCars() -- Clear all checkpoints C#############################C#############################Cl############################-- start race w########-###t#####i#####ycle StartLightCycle() -- remove barrier removeBarrier() RaceInProgress = true -- wait for race to finish while RaceInProgress == true do wait() end wait (5) -- delete all cars DestroyCars() wait(2) -- teleport players to lobby teleportPlayers(lobbySpawn) wait(10) end
KEVEKEV77
#223892403Friday, August 18, 2017 11:31 PM GMT

let me first off tell you the first one you posted SHOULD crash your computer, you didnt put a wait inside the first while loop
BunnyBoy26
#223892553Friday, August 18, 2017 11:34 PM GMT

@KEV From a quick glance I see a wait(5), wait(2), and a wait(10) in the outer loop.
KEVEKEV77
#223892747Friday, August 18, 2017 11:39 PM GMT

local MinimumPlayers = 2 while true do --wait for enough players before we start the game while game.Players.Numplayers < MinimumPlayers do wait() end hm get some glasses
BunnyBoy26
#223892897Friday, August 18, 2017 11:42 PM GMT

while true do -- FIRST DO HERE --wait for enough players before we start the game while game.Players.Numplayers < MinimumPlayers do -- SECOND DO HERE wait() end -- ONLY ONE END You are the one who needs glasses.
MichaelRaptor
#223892930Friday, August 18, 2017 11:43 PM GMT

while true do --wait for enough players before we start the game while game.Players.Numplayers < MinimumPlayers do wait() are you saying I should change it to something more like while true do --wait for enough players before we start the game while game.Players.Numplayers < MinimumPlayers do wait(1) end
MichaelRaptor
#223892977Friday, August 18, 2017 11:44 PM GMT

while true do --wait for enough players before we start the game while game.Players.Numplayers < MinimumPlayers do wait(1) end end So I need 2 ends is the problem?
BunnyBoy26
#223893066Friday, August 18, 2017 11:46 PM GMT

You have the end for the first while loop at the very end of the script by the looks of it. Is there any output?
MichaelRaptor
#223893115Friday, August 18, 2017 11:47 PM GMT

Yes, The output says "Numplayers is not a valid member of Players" I just saw it say that
BunnyBoy26
#223893147Friday, August 18, 2017 11:48 PM GMT

Well that helps. NumPlayers Capital P
Ezuras
#223893183Friday, August 18, 2017 11:49 PM GMT

replace while game.Players.numplayers with game.Players.NumPlayers
MichaelRaptor
#223893462Friday, August 18, 2017 11:55 PM GMT

I did it but for some reason, even with 2 or 3 players it still doesn't teleport them to the track like I have it set up to do. But still, no error message is displayed in output.
BunnyBoy26
#223893629Saturday, August 19, 2017 12:00 AM GMT

Try sprinkling in some print statements?
MichaelRaptor
#223893736Saturday, August 19, 2017 12:02 AM GMT

I did while true do --wait for enough players before we start the game print ("I am going to wait until there are more players") while game.Players.NumPlayers < MinimumPlayers do wait() end end And it did print. But it still doesn't continue the code after there are 2 players. If it detected 2 players it is supposed to allow the code below to begin which starts the race
BunnyBoy26
#223893848Saturday, August 19, 2017 12:05 AM GMT

Did you place that second end right after the previous one? If so, delete that. You could also put a print after the inner while loop.
MichaelRaptor
#223893861Saturday, August 19, 2017 12:05 AM GMT

When I tested it with 2 players, before the players loaded it printed what I told it to. Then, when the 2 players loaded it printed again. But they never did get teleported.
MichaelRaptor
#223893968Saturday, August 19, 2017 12:08 AM GMT

When I deleted the second end the whole thing bugged out
BunnyBoy26
#223894351Saturday, August 19, 2017 12:16 AM GMT

Can you be more specific?
MichaelRaptor
#223894422Saturday, August 19, 2017 12:18 AM GMT

while true do --wait for enough players before we start the game print ("I am going to wait until there are more players") while game.Players.NumPlayers < MinimumPlayers do wait() end end you said to delete one of the ends. I did, and it caused the whole code to mess up because there are 2 whiles in the code so 2 ends are needed for it to work.
MichaelRaptor
#223894489Saturday, August 19, 2017 12:20 AM GMT

I also tried this and it failed to work while true do --wait for enough players before we start the game print ("I am going to wait until there are more players") while game.Players.NumPlayers < MinimumPlayers do wait() while game.Players.NumPlayers > MinimumPlayers do print("There are enough players now") end end end
BunnyBoy26
#223894602Saturday, August 19, 2017 12:22 AM GMT

Yes, you should have two while loops and two ends. The first end (for the inner while loop) should be where it is now. The second end (for the outer while loop) needs to go at the end of the script (after the teleporting, etc.)

    of     2   
chevron_rightchevron_rightchevron_right