|
| 10 Nov 2014 04:34 PM |
I have a script that teleports all players to a location every few seconds. It does this by accessing the player list and moving their character using the reference point there. However, if the player dies while the script is looking for player.Character, there won't be a player.Character to find. How would I go about fixing this? Is there some sort of check I can do? I'd do FindFirstChild but does that even work in a scenario like this, because I couldn't get it to work.
ExploreTime = 5 ExploreTimeLeft = ExploreTime
while true do wait(1) community = game.Players:GetChildren() ExploreTimeLeft = ExploreTimeLeft - 1
for i = 1, #community do
if ExploreTimeLeft == 0 then randompick = math.random(2) if randompick == 1 then GameChoice = workspace.Homeplate1 elseif randompick == 2 then GameChoice = workspace.Homeplate2 end community[i].Character.Torso.CFrame = CFrame.new(GameChoice.Position) ExploreTimeLeft = ExploreTime end community[i].PlayerGui.ScreenGui.TimeLeft.Text = ExploreTimeLeft end end |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
| |
|
|
| 10 Nov 2014 08:15 PM |
| Wow it's really that simple? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 10 Nov 2014 08:16 PM |
| mmhm, the Character property holds a reference to the character, so if it doesn't exist it will be nil |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2014 08:21 PM |
So then
-- if player.Character then --
means that if player.Character isn't nil, do this thing.
Ok, I'll try that.
|
|
|
| Report Abuse |
|
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 10 Nov 2014 09:28 PM |
Try this if Player.Character ~= nil then |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2014 10:24 PM |
@Ojia
if Player.Character then is the same as
if Player.Character ~= nil then |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 10 Nov 2014 10:28 PM |
| Not the exact same, but in this case it basically is |
|
|
| Report Abuse |
|
|