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: Theres gotta be a more efficient way to do this

Previous Thread :: Next Thread 
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
04 Jun 2014 03:49 AM
Basically I want to see the number of players that are STILL ALIVE
Right now i'm using a while loop for each player and game.Players:FindFirstChilding to see if they left the server or not.

I'm pretty sure game.Players.PlayerRemoving wont work in a LocalScript, soo...

The reason I'm not using a server-side script is because there is also another part that'll be too many while loops for a server to handle.

tl;dr. Make this more efficient without PlayerRemoving plz



for i, v in pairs(game.Players:GetPlayers()) do
if v.Character then
local pp = false
counter = counter + 1
v.Character.Humanoid.Died:connect(function()
script.Plrs.Value = script.Plrs.Value-1
pp = true
end)
Spawn(function()
while pp do
wait()
if not game.Players:FindFirstChild(v.Name) then
pp = false
script.Plrs.Value=script.Plrs.Value-1
end
end
end)
end
end
Report Abuse
roxmat is not online. roxmat
Joined: 10 Jun 2011
Total Posts: 66
04 Jun 2014 03:57 AM
Just have something to check if each player has the value "Alive".

So like

for i,v in pairs(game.Players:GetChildren()) do
if v.PlayerGui.Value.Value == "Alive" then
counter = counter + 1
end
if v.PlayerGui.Value.Value == "Dead" then
counter = counter - 1
end
end

It's not the best.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
04 Jun 2014 04:01 AM
That was the other thing I was trying to avoid... but i guess thats a solution...
Report Abuse
nomer888 is online. nomer888
Joined: 13 Feb 2010
Total Posts: 551
04 Jun 2014 04:02 AM
It could be me at 2:00 AM being tired and all, but I don't see why LocalScripts can't listen to game.Players' events. Have you tried using .ChildRemoved and .PlayerRemoving already?
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
04 Jun 2014 04:16 AM
its weird but it doesnt work with child/playerremoving
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
04 Jun 2014 04:18 AM
Well, its best, but u can make value somewhere, change it in serverside script, then .Changed event local
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