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 » Scripting Helpers
Home Search
 

Re: A short 20 lines of failure.

Previous Thread :: Next Thread 
sharkSquid is not online. sharkSquid
Joined: 30 Sep 2011
Total Posts: 32
02 Oct 2011 01:05 PM
local debris = game:GetService("Debris")
_G.alive = {}
_G.dead = {}

while game.Players.NumPlayers >= 1 do
local hint = Instance.new("Hint", game.Workspace)
hint.Text = "There are a sufficient amount of players in the lobby. Your game will begin shortly."
wait(10)
hint.Text = "A minigame is being selected."
wait(5)
hint.Text = "A minigame was selected!"
wait(5)
hint.Text = "You will be transported to your minigame momentarily."
wait(3)
local g = game.Players:GetPlayers()
for i = 1, #g do
local pchar = g[i].Character
if pchar then
local tor = pchar:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(50, 5, 50)
table.insert(_G.alive, g[i].Name)
end
end
end
end

This script fails from the absolute beginning. It doesn't even add in the hint when I join in online mode. No output.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
02 Oct 2011 01:08 PM
The while loop is a pretest loop. When the server starts, there are no players in the game, which ends the loop before it even starts.
Report Abuse
sharkSquid is not online. sharkSquid
Joined: 30 Sep 2011
Total Posts: 32
02 Oct 2011 01:10 PM
So what should I do?

game.Players.PlayerAdded:wait()

?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
02 Oct 2011 01:11 PM
You COULD do that, but I recommend putting your current loop inside an infinite loop.
Report Abuse
Wil2 is not online. Wil2
Joined: 01 Feb 2008
Total Posts: 728
02 Oct 2011 01:12 PM
local debris = game:GetService("Debris")
_G.alive = {}
_G.dead = {}
ps = game:GetService("Players")
script.Parent = nil
--the 2 lines above this line keeps script from being deleted and broken if game gets hacked.

while true do
local pls = ps:GetPlayers()
if #pls > 0 then
if pls >= 2 then
local hint = Instance.new("Hint", game.Workspace)
hint.Text = "There are a sufficient amount of players in the lobby. Your game will begin shortly."
wait(10)
hint.Text = "A minigame is being selected."
wait(5)
hint.Text = "A minigame was selected!"
wait(5)
hint.Text = "You will be transported to your minigame momentarily."
wait(3)
local g = game.Players:GetPlayers()
for i = 1, #g do
local pchar = g[i].Character
if pchar then
local tor = pchar:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(50, 5, 50)
table.insert(_G.alive, g[i].Name)
end
end
end end end
wait()
end
Report Abuse
sharkSquid is not online. sharkSquid
Joined: 30 Sep 2011
Total Posts: 32
02 Oct 2011 02:49 PM
Here's the current version:

local debris = game:GetService("Debris")
_G.alive = {}
_G.dead = {}

while true do
local players = game.Players:GetPlayers()
if #players >= 1 then --Remember to change this line.
local hint = Instance.new("Hint", game.Workspace)
hint.Text = "There are a sufficient amount of players in the lobby. Your game will begin shortly."
wait(10)
hint.Text = "A minigame is being selected."
wait(5)
hint.Text = "A minigame was selected!"
wait(5)
hint.Text = "You will be transported to your minigame momentarily."
wait(3)
local player = game.Players:GetPlayers()
for i = 1, #player do
local pchar = player[i].Character
if pchar then
local tor = pchar:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(50, 5 * i, 50)
table.insert(_G.alive, player[i].Name)
end
end
end
end
end

I can't tell if there is output or not, because whenever I try and push the green arrow in ROBLOX Studio, it shuts ROBLOX down. Nothing happens in online mode.
Report Abuse
Wil2 is not online. Wil2
Joined: 01 Feb 2008
Total Posts: 728
02 Oct 2011 03:03 PM
reason for it to shut roblox down is because you need a wait in the loop or in the for, use my version
Report Abuse
sharkSquid is not online. sharkSquid
Joined: 30 Sep 2011
Total Posts: 32
02 Oct 2011 03:39 PM
@Wil

Do you not see the three wait()s I include in this script?
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
02 Oct 2011 03:45 PM
No, wil is correct.

local debris = game:GetService("Debris")
_G.alive = {}
_G.dead = {}

while wait() do
local players = game.Players:GetPlayers()
if #players >= 1 then --Remember to change this line.
local hint = Instance.new("Hint", game.Workspace)
hint.Text = "There are a sufficient amount of players in the lobby. Your game will begin shortly."
wait(10)
hint.Text = "A minigame is being selected."
wait(5)
hint.Text = "A minigame was selected!"
wait(5)
hint.Text = "You will be transported to your minigame momentarily."
wait(3)
local player = game.Players:GetPlayers()
for i = 1, #player do
local pchar = player[i].Character
if pchar then
local tor = pchar:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(50, 5 * i, 50)
table.insert(_G.alive, player[i].Name)
end
end
end
end
end


-Like an __AWESOME__ boss
Report Abuse
sharkSquid is not online. sharkSquid
Joined: 30 Sep 2011
Total Posts: 32
02 Oct 2011 03:47 PM
@ElectricBlaze

May I ask what you changed?
Report Abuse
Horanoven is not online. Horanoven
Joined: 11 Jul 2008
Total Posts: 11034
02 Oct 2011 03:54 PM
From what I can tell, all the waits are AFTER the if statement. If the 'if' statement doesn't fire, the waits are never reached therefore the game crashes. Put a wait before that 'if' statement.

local debris = game:GetService("Debris")
_G.alive = {}
_G.dead = {}

while true do
wait(0.1)
local players = game.Players:GetPlayers()
if #players >= 1 then --Remember to change this line.
local hint = Instance.new("Hint", game.Workspace)
hint.Text = "There are a sufficient amount of players in the lobby. Your game will begin shortly."
wait(10)
hint.Text = "A minigame is being selected."
wait(5)
hint.Text = "A minigame was selected!"
wait(5)
hint.Text = "You will be transported to your minigame momentarily."
wait(3)
local player = game.Players:GetPlayers()
for i = 1, #player do
local pchar = player[i].Character
if pchar then
local tor = pchar:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(50, 5 * i, 50)
table.insert(_G.alive, player[i].Name)
end
end
end
end
end
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
02 Oct 2011 03:55 PM
@shark - I changed while true do to while wait() do so that it waits no matter how many players there are


-Like an __AWESOME__ boss
Report Abuse
Wil2 is not online. Wil2
Joined: 01 Feb 2008
Total Posts: 728
02 Oct 2011 03:56 PM
that too, but wait() won't crash game either, it'll make the script wait by 1 frame
Report Abuse
Horanoven is not online. Horanoven
Joined: 11 Jul 2008
Total Posts: 11034
02 Oct 2011 03:57 PM
A 'while wait() do' statement? I can't say I knew that could be done.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
02 Oct 2011 03:58 PM
@Hora - It can, it simply waits 1 frame at the start of each loop.


-Like an __AWESOME__ boss
Report Abuse
Horanoven is not online. Horanoven
Joined: 11 Jul 2008
Total Posts: 11034
02 Oct 2011 03:59 PM
@ElectricBlaze

That is a neat trick. I'll have to remember that.
Report Abuse
moustachauve is not online. moustachauve
Joined: 29 Jul 2009
Total Posts: 668
02 Oct 2011 04:00 PM
@Hora, when you do something like
while wait() do
or
if wait() then

it will execute the function you said in the middle, in this case, it will stop the script for a frame, then the function return true if it succeed, then it continue the script
Report Abuse
sharkSquid is not online. sharkSquid
Joined: 30 Sep 2011
Total Posts: 32
02 Oct 2011 04:15 PM
Workspace.sourceCode:33: ')' expected (to close '(' at line 26) near 'end'


local debris = game:GetService("Debris")
_G.alive = {}
_G.dead = {}

while wait() do
local players = game.Players:GetPlayers()
if #players >= 1 then --Remember to change this line.
local hint = Instance.new("Hint", game.Workspace)
hint.Text = "There are a sufficient amount of players in the lobby. Your game will begin shortly."
wait(10)
hint.Text = "A minigame is being selected."
wait(5)
hint.Text = "A minigame was selected!"
wait(5)
hint.Text = "You will be transported to your minigame momentarily."
wait(3)
local player = game.Players:GetPlayers()
for i = 1, #player do
local pchar = player[i].Character
if pchar then
local tor = pchar:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(50, 5 * i, 50)
table.insert(_G.alive, player[i].Name)
hint.Text = "Alive: "..table.concat(_G.alive, " ")
coroutine.resume(coroutine.create(function() --Line 26
local num = 0
repeat
player[i].survivePoints.Value = player[i].survivePoints.Value + 1
wait(1)
until player[i].Character.Humanoid.Health == 0
end)
end) --Line 33
end
end
end
end
end

This is what I had before (including the while wait() part), but with an extra coroutine part. There is output, and I have the lines marked.
Report Abuse
Wil2 is not online. Wil2
Joined: 01 Feb 2008
Total Posts: 728
02 Oct 2011 04:20 PM
local debris = game:GetService("Debris")
_G.alive = {}
_G.dead = {}

while wait() do
local players = game.Players:GetPlayers()
if #players >= 1 then --Remember to change this line.
local hint = Instance.new("Hint", game.Workspace)
hint.Text = "There are a sufficient amount of players in the lobby. Your game will begin shortly."
wait(10)
hint.Text = "A minigame is being selected."
wait(5)
hint.Text = "A minigame was selected!"
wait(5)
hint.Text = "You will be transported to your minigame momentarily."
wait(3)
local player = game.Players:GetPlayers()
for i = 1, #player do
local pchar = player[i].Character
if pchar then
local tor = pchar:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(50, 5 * i, 50)
table.insert(_G.alive, player[i].Name)
hint.Text = "Alive: "..table.concat(_G.alive, " ")
coroutine.resume(coroutine.create(function() --Line 26
local num = 0
repeat
player[i].survivePoints.Value = player[i].survivePoints.Value + 1
wait(1)
until player[i].Character.Humanoid.Health == 0
end)
end)) --Fixed
end
end
end
end
end
Report Abuse
sharkSquid is not online. sharkSquid
Joined: 30 Sep 2011
Total Posts: 32
02 Oct 2011 04:30 PM
@Wil2

Still doesn't work, same output.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
02 Oct 2011 04:33 PM
local debris = game:GetService("Debris")
_G.alive = {}
_G.dead = {}

while wait() do
local players = game.Players:GetPlayers()
if #players >= 1 then --Remember to change this line.
local hint = Instance.new("Hint", game.Workspace)
hint.Text = "There are a sufficient amount of players in the lobby. Your game will begin shortly."
wait(10)
hint.Text = "A minigame is being selected."
wait(5)
hint.Text = "A minigame was selected!"
wait(5)
hint.Text = "You will be transported to your minigame momentarily."
wait(3)
local player = game.Players:GetPlayers()
for i = 1, #player do
local pchar = player[i].Character
if pchar then
local tor = pchar:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(50, 5 * i, 50)
table.insert(_G.alive, player[i].Name)
hint.Text = "Alive: "..table.concat(_G.alive, " ")
coroutine.resume(coroutine.create(function() --Line 26
local num = 0
repeat
player[i].survivePoints.Value = player[i].survivePoints.Value + 1
wait(1)
until player[i].Character.Humanoid.Health == 0
end))
end
end
end
end
end
end
Report Abuse
sharkSquid is not online. sharkSquid
Joined: 30 Sep 2011
Total Posts: 32
02 Oct 2011 04:39 PM
@AFF

Thank you. Now there is no output, but a few more errors (ugh).

The hint won't display the people in the table:

hint.Text = "Alive: "..table.concat(_G.alive, " ")

Instead, when it reaches this part, it just restarts the whole loop.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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