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 » Scripters
Home Search
 

Re: Script breaks when a player leaves.

Previous Thread :: Next Thread 
Lem0nzzz is not online. Lem0nzzz
Joined: 01 Sep 2014
Total Posts: 521
18 Apr 2015 02:01 PM
So I have a script that creates 2 random players.

Plrs = game.Players:GetChildren()
local plr1 = Plrs[math.random(1, #Plrs)]
game.Lighting.Values.plr1value.Value = plr1.Name
repeat
wait() plr2 = Plrs[math.random(1, #Plrs)]
until plr2.Name ~= plr1.Name and plr2 ~= nil
game.Lighting.Values.plr2value.Value = plr2.Name

The issue is, if a player leaves, the stored variable is now nil, so if I was to try to teleport that player, it'd break the script because there's no player. How can I fix this?
Report Abuse
Lem0nzzz is not online. Lem0nzzz
Joined: 01 Sep 2014
Total Posts: 521
18 Apr 2015 02:12 PM
Bump.
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
18 Apr 2015 02:14 PM
--This should do the trick.
--Also don't use lighting to store things you should use serverstorage.

p1 = nil
p2 = nil

function getplayers()
local Plrs = game.Players:GetChildren()
p1 = nil--Make them nil so the script won't use old players.
p2 = nil
if #Plrs <= 1 then wait(0.5) return end--So it won't try to add two players when there is only one.
p1 = Plrs[math.random(1, #Plrs)]
game.Lighting.Values.plr1value.Value = p1.Name
repeat wait()
p2 = Plrs[math.random(1, #Plrs)]
until p2.Name ~= p1.Name
game.Lighting.Values.plr2value.Value = p2.Name
end

function check()--So just run this everytime you want to do something with the random players?
if p1 and p2 then
--run code for them?
else
getplayers()
check()
end
end

getplayers()
check()
Report Abuse
matt1020304050 is not online. matt1020304050
Joined: 24 May 2008
Total Posts: 4475
18 Apr 2015 02:20 PM
Please tell me why the lighting can't be used as storage, it's deprecated. But I see no negative effect on a game that it could cause.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
18 Apr 2015 02:27 PM
Not as secure and was not intended to be used as storage in the first place.
Report Abuse
Lem0nzzz is not online. Lem0nzzz
Joined: 01 Sep 2014
Total Posts: 521
18 Apr 2015 02:31 PM
Well thanks for helping me out with the script. But you did fix one thing.. You made it so if the player leaves, it waits til they rejoin and then it continues and tps, but the issue is what if they don't come back?
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
18 Apr 2015 02:43 PM
It should pick new players. :P
Report Abuse
matt1020304050 is not online. matt1020304050
Joined: 24 May 2008
Total Posts: 4475
18 Apr 2015 02:49 PM
Secure how?
Report Abuse
Lem0nzzz is not online. Lem0nzzz
Joined: 01 Sep 2014
Total Posts: 521
18 Apr 2015 04:39 PM
I don't understand why you have to comment on why I put something in lighting, instead of an efficient way that in your opinion is a better way to store something. Sure, it's a storage system, but almost everything on the tree is storable. You can choose to make it secure or not.
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
18 Apr 2015 04:43 PM
@Matt, think of it this way, ServerStorage can't be accessed by clients, whereas anyone can see any descendants and contents of lighting, another con with lighting is rather than it keeping little to data as possible until the item is communicated with, lighting is as bad as having those instances existing but simply hiding them under a blanket.

This is similar to

:remove() = hide
:Destroy() = get rid of

Whereas

Lighting = Have tons of junky data
ServerStorage = Still accessible, but isn't rendered and is nil for clients
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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