miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 31 Dec 2011 11:45 AM |
local m = Instance.new("Message",Workspace) pcall(function() if game.Players.NumPlayers <=2 then m.Text = "You need at least 3 players to play" else m:Destroy() end end)
It works half way. Meaning, the message pops up when there's less than 2 players in a game. But the else statement doesn't run. Why... |
|
|
| Report Abuse |
|
|
C0D3Y
|
  |
| Joined: 24 Jul 2010 |
| Total Posts: 1692 |
|
|
| 31 Dec 2011 11:46 AM |
| You destroy it if there's an else. So nothing should happen... |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 31 Dec 2011 11:49 AM |
m = Instance.new("Message",Workspace) pcall(function() if game.Players.NumPlayers <=2 then m.Text = "You need at least 3 players to play" end if game.Players.NumPlayers >=3 then m:Destroy() end end)
Why not now? Same thing. |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2011 11:53 AM |
Your first should've worked.
if ARG then --Things else -- means if it's anything else than what was specified in the first if statement (ARG) --Other things end
If you wish to have multiple "if"s in a statement, you can do
if ARG then --Things elseif ARG2 then --Other things else -- Anything else than ARG and ARG2 --More things end
Anyhow - your problem.. I have no idea. Though, I'm not very used to pcall. I'll see if I can find a solution. |
|
|
| Report Abuse |
|
|
C0D3Y
|
  |
| Joined: 24 Jul 2010 |
| Total Posts: 1692 |
|
|
| 31 Dec 2011 11:53 AM |
| If the number of players is more than 3, nothing will happen... Oh. Wait, I get it now... You want that to stay on the screen until you a third person comes... Hm... why are you using Pcall? Just curious, I don't really see a need for it... |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 31 Dec 2011 12:02 PM |
| I'm using a pcall() because if someone goes the message pops up again instead of just working once. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 31 Dec 2011 12:03 PM |
| Anyone know why it doesn't work? |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
|
| 31 Dec 2011 12:21 PM |
| know this is probably wrong but you could use a loop after the creation of the message and before you delete it |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2011 12:34 PM |
You could use a repeat loop
if game.Players.NumPlayers < 3 then m = Instance.new("Message", game.Workspace) m.Text = "You need at least three people to play" repeat wait() until game.Players.NumPlayers >= 3 --Suppose 2 came in at once? m:Destroy() Start Game else Start Game end |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 31 Dec 2011 12:44 PM |
@bl5
I can't have a repeat because pcall() can't have waits. |
|
|
| Report Abuse |
|
|
Chronok
|
  |
| Joined: 29 Dec 2011 |
| Total Posts: 402 |
|
|
| 31 Dec 2011 12:56 PM |
if #game:GetService("Players"):GetPlayers() <= 2 then local m = Instance.new("Hint", game.Workspace) m.Text = "You need at least three players to play." else return end
{ Chronok, novitiate scripter/programmer. } |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
Chronok
|
  |
| Joined: 29 Dec 2011 |
| Total Posts: 402 |
|
|
| 31 Dec 2011 01:01 PM |
Or if this is a small chunk of a larger script (which is probably the case), try this:
if #game:GetService("Players"):GetPlayers() <= 2 then local m = Instance.new("Hint", game.Workspace) m.Text = "You need at least three players to play." else print("There are more than three players.") -- Can't have return ending the script, now can we? end
{ Chronok, novitiate scripter/programmer. } |
|
|
| Report Abuse |
|
|
Jaccob
|
  |
| Joined: 19 Oct 2008 |
| Total Posts: 986 |
|
|
| 31 Dec 2011 01:23 PM |
Players = 3 if #game.Players:GetChildren() < Players then repeat wait() wait(3) msg = Instance.new("Message", Workspace) msg.Text = "We need 3 or more people to start the game" wait(3) msg:remove() until #game.Players:GetChildren() >= Players wait(5) end
If this is what you need, pcall is uneeded for this anywho. It's a simple script I threw together that your probably want. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 31 Dec 2011 04:03 PM |
| I'ma just rewrite the code if I don't need a pcall... |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2011 04:14 PM |
WAIT
m = Instance.new("Message",Workspace) while true do pcall(function() if game.Players.NumPlayers <=2 then m.Text = "You need at least 3 players to play" end end if game.Players.NumPlayers >=3 then m:Destroy() end end)
|
|
|
| Report Abuse |
|
|
| |
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|