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: message

Previous Thread :: Next Thread 
Kasumo is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 07:53 PM
Or even more efficiently: Game.Players.NumPlayers
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
24 Jul 2014 07:53 PM
ohhhh
Report Abuse
128GB is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. Azureous
Joined: 29 Jan 2012
Total Posts: 25287
24 Jul 2014 07:58 PM
She*

>_<
Report Abuse
cntkillme is not online. 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 is not online. Azureous
Joined: 29 Jan 2012
Total Posts: 25287
24 Jul 2014 07:59 PM
lol
Report Abuse
Thetacahalt is not online. Thetacahalt
Joined: 18 Jan 2014
Total Posts: 163
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 is not online. 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 is not online. 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
Thetacahalt is not online. Thetacahalt
Joined: 18 Jan 2014
Total Posts: 163
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
24 Jul 2014 08:18 PM
nvm i fixed it
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