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
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 521 |
|
| |
|
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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 18 Apr 2015 02:43 PM |
| It should pick new players. :P |
|
|
| Report Abuse |
|
|
| |
|
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
|
  |
| 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 |
|
|