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: Any reason why this simple script won't work?

Previous Thread :: Next Thread 
miz656 is not online. 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 is not online. 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 is not online. 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
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
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 is not online. 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 is not online. 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 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
31 Dec 2011 12:03 PM
Anyone know why it doesn't work?
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
31 Dec 2011 12:19 PM
Bump.
Report Abuse
shaythegoon is not online. shaythegoon
Joined: 18 Jul 2010
Total Posts: 630
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
bl5eebryce is not online. bl5eebryce
Joined: 03 Aug 2009
Total Posts: 387
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 is not online. 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 is not online. 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 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
31 Dec 2011 01:00 PM
@Chornok

Nope
Report Abuse
Chronok is not online. 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 is not online. 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 is not online. 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
shaythegoon is not online. shaythegoon
Joined: 18 Jul 2010
Total Posts: 630
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
shaythegoon is not online. shaythegoon
Joined: 18 Jul 2010
Total Posts: 630
31 Dec 2011 04:15 PM
probably wont work ^^^
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
31 Dec 2011 04:21 PM
Nope.
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