Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
|
| 24 Jul 2014 07:49 PM |
when there are 2 or more players(i changed it to 1 for testing), it's supposed to print "p" and make a message, and it SHOULD BE WORKING, but it's not.
v=Instance.new("IntValue",script) v.Value = 0 game.Players.PlayerAdded:connect(function() v.Value = v.Value + 1 end) game.Players.PlayerRemoving:connect(function() v.Value = v.Value - 1 end) if (v.Value >= 1) then print("p") m=Instance.new("Message",game.Workspace) m.Text = "2 or players have entered" wait(2) m.Text = "Game will begin shortly.." wait(3) m:remove() end
|
|
|
| Report Abuse |
|
|
Azureous
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25287 |
|
|
| 24 Jul 2014 07:52 PM |
| Use a Changed event on the NumPlayers property of Player Service that returns the current number of players - no loops and no unreliable event-function connections |
|
|
| Report Abuse |
|
|
Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
|
| 24 Jul 2014 07:52 PM |
okay, i know it's
if (v.Value >= 1) then
because i changed it to
if (1 + 1 ==2) then
and it printed "p" and made the message |
|
|
| Report Abuse |
|
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
|
| 24 Jul 2014 07:52 PM |
Umh, you're supposed to run:
"if (v.Value >= 1) then print("p") m=Instance.new("Message",game.Workspace) m.Text = "2 or players have entered" wait(2) m.Text = "Game will begin shortly.." wait(3) m:remove() end"
Inside the PlayerAdded event, otherwise it will only run once, which is when the server starts, and at that point there will only be 1 player... OR, you can do:
repeat wait() until v.Value >= 2 print("p") m=Instance.new("Message",game.Workspace) m.Text = "2 or players have entered" wait(2) m.Text = "Game will begin shortly.." wait(3) m:remove()
BTW, if you want to get the numbers of players more efficiently, you can do : #Game.Players:GetPlayers() |
|
|
| Report Abuse |
|
|
Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
|
| 24 Jul 2014 07:53 PM |
| i don't know how to use numplayers that's why i did this |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 07:53 PM |
| Or even more efficiently: Game.Players.NumPlayers |
|
|
| Report Abuse |
|
|
Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
| |
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 24 Jul 2014 07:54 PM |
'Use a Changed event on the NumPlayers property ' You can't use an event on a property |
|
|
| Report Abuse |
|
|
Azureous
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25287 |
|
|
| 24 Jul 2014 07:55 PM |
| @128GB make an IntValue that equals the NumPlayers and when it changes <_< didn't explain that sorry |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 24 Jul 2014 07:57 PM |
ummm Hows that work? You'd have to constantly update the int value |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 07:57 PM |
He means: IntValue.Value.Changed
datatypes don't have a Changed member, however IntValue.Changed will work and the upvalue returned is the newvalue (or in non int/string/etcValues, the key (property) that was changed) |
|
|
| Report Abuse |
|
|
Azureous
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25287 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 07:58 PM |
| I was talking about 128's comment, to you (I explained that bad) |
|
|
| Report Abuse |
|
|
Azureous
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25287 |
|
| |
|
|
| 24 Jul 2014 08:03 PM |
while (true) do; if game.Players.NumPlayers <=2 then m=Instance.new("Message",game.Workspace) m.Text = "2 or players have entered" wait(2) m.Text = "Game will begin shortly.." wait(3) m:remove() end end |
|
|
| Report Abuse |
|
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
|
| 24 Jul 2014 08:05 PM |
@Thetacahalt
That will potentially crash the game, do "while wait() do" instead |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 08:06 PM |
Or even better:
while game.Players.NumPlayers < 2 do game.Players.PlayerAdded:wait(); end |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2014 08:09 PM |
@luc, I have more efficient ways if I were going to make this script, I was just making a script from the way he was attempting to do:)
@cnt, true |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 24 Jul 2014 08:11 PM |
| Its not 'more efficient' to make a script not break the game ok its called making a working script |
|
|
| Report Abuse |
|
|
fret13103
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 881 |
|
|
| 24 Jul 2014 08:11 PM |
or
game.Players.PlayerAdded:connect(function(player) if game.NumPlayers>=2 then p = Instance.new"Message" p.Parent = Workspace p.Text = "p" wait(10) p.Parent = game.Debris end end) end
|
|
|
| Report Abuse |
|
|
Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
|
| 24 Jul 2014 08:13 PM |
okay, it's working now. i added this line after it though. but it's not moving the characters.
p = game.Players:GetPlayers() for i = 1,#p do p[i].Character:MoveTo(game.Workspace.Part.Position) end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 08:16 PM |
I'ma swag it with more efficiency and shortness
local p=Game.Players;while p.NumPlayers<2 do p.PlayerAdded:wait();end |
|
|
| Report Abuse |
|
|
Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
| |
|