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: How to check if a player's character exists.

Previous Thread :: Next Thread 
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
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 is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
10 Nov 2014 04:38 PM
if player.Character then
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
10 Nov 2014 08:15 PM
Wow it's really that simple?
Report Abuse
cntkillme is not online. 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
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
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 is not online. Ojia
Joined: 08 Feb 2012
Total Posts: 650
10 Nov 2014 09:28 PM
Try this
if Player.Character ~= nil then
Report Abuse
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
10 Nov 2014 10:24 PM
@Ojia

if Player.Character then is the same as

if Player.Character ~= nil then
Report Abuse
cntkillme is not online. 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
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