generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Help I've got a scripting error

Previous Thread :: Next Thread 
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 06:25 PM
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
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 06:27 PM
I hope this isn't the whole script.
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 06:28 PM
It's not the whole script for the game. I'll post the whole game's script if neccasery
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
18 Aug 2017 06:28 PM
You have to add the code that starts the game.....
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 06:29 PM
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
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
18 Aug 2017 06:31 PM
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
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 06:34 PM
@KEV From a quick glance I see a wait(5), wait(2), and a wait(10) in the outer loop.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
18 Aug 2017 06:39 PM
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
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 06:42 PM
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.
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 06:43 PM
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


Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 06:44 PM
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?
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 06:46 PM
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?
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 06:47 PM
Yes, The output says "Numplayers is not a valid member of Players"
I just saw it say that
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 06:48 PM
Well that helps.

NumPlayers

Capital P
Report Abuse
Ezuras is online. Ezuras
Joined: 07 Nov 2012
Total Posts: 8768
18 Aug 2017 06:49 PM
replace while game.Players.numplayers with game.Players.NumPlayers
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 06:55 PM
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.
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 07:00 PM
Try sprinkling in some print statements?
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 07:02 PM
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
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 07:05 PM
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.
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 07:05 PM
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.
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 07:08 PM
When I deleted the second end the whole thing bugged out
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 07:16 PM
Can you be more specific?
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 07:18 PM
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.
Report Abuse
MichaelRaptor is online. MichaelRaptor
Joined: 12 Oct 2014
Total Posts: 88
18 Aug 2017 07:20 PM
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
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
18 Aug 2017 07:22 PM
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.)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image