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: Better Way to Wait for a Character?

Previous Thread :: Next Thread 
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
30 Dec 2013 12:20 AM
if player.Character then
while player.Character.Health < 1 do
wait()
end
end
while player.Character == nil do
wait()
end

local Contain = Instance.new("Message",player.Character)


That is the crap I have to do to get the correct Character... Is there a better way?
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
30 Dec 2013 12:23 AM
... noob

function onPlayerAdded(plr)
plr.CharactedAdded:connect(function()...


or

repeat wait() until player.Character
Report Abuse
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
30 Dec 2013 12:23 AM
Checking the Humanoid's health and not the model's health would be a good place to start...


FYI This is in a GUI
Report Abuse
TheOneSwordfighter is not online. TheOneSwordfighter
Joined: 18 Feb 2013
Total Posts: 212
30 Dec 2013 12:25 AM
local char=plr.CharacterAdded:wait() -- for pros

~LuaWeaver; Programmer, gamer, developer.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
30 Dec 2013 12:30 AM
^
That only gets it once, and even halts the code.

Bad bad.
Report Abuse
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
30 Dec 2013 12:31 AM
"That only gets it once, and even halts the code."


Um, that's all I want and need :P
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
30 Dec 2013 01:23 AM
You don't understand, if it's ran too late, it will keep waiting (most likely forever, if that what you say is true, and that is all you say you need).
Report Abuse
NVI is not online. NVI
Joined: 11 Jan 2009
Total Posts: 4744
30 Dec 2013 01:29 AM
Yeah, there's a chance your code could end up waiting forever if it runs after the CharacterAdded event is fired. I don't think that's what you want.
Report Abuse
TheOneSwordfighter is not online. TheOneSwordfighter
Joined: 18 Feb 2013
Total Posts: 212
30 Dec 2013 01:30 AM
I figured he's wrapping it in, you know, the if statement prior.
Except corrected.

~LuaWeaver; Programmer, gamer, developer.
Report Abuse
Fluffmiceter is not online. Fluffmiceter
Joined: 28 Jan 2012
Total Posts: 6931
30 Dec 2013 08:34 AM
player:WaitForChild("Character")

or

player.CharacterAdded:wait()
Report Abuse
littleAU999 is not online. littleAU999
Joined: 15 Jan 2011
Total Posts: 1375
30 Dec 2013 09:23 AM
@fluff
Character isnt a child of player
its a property
Report Abuse
200AB is not online. 200AB
Joined: 24 Aug 2010
Total Posts: 1604
30 Dec 2013 12:14 PM
while (not player.Character) do wait() end


^thats the best you can get
Report Abuse
Cutiegirl572 is online. Cutiegirl572
Joined: 14 Jan 2009
Total Posts: 28
30 Dec 2013 12:36 PM
@200AB,
lets go a little rogue here

for i = 1, math.huge do
wait()
if player.Character then
break
end
end
Report Abuse
MettaurSp is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
30 Dec 2013 01:22 PM
Wat. Cnt needs to post his cntified code now o3o
Report Abuse
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
30 Dec 2013 02:40 PM
It's funny because for whatever reason Roblox will start up the new GUI before the new Character is made. So the character is just a dead other character while the GUI is starting up which is really annoying...
Report Abuse
Merely is not online. Merely
Joined: 07 Dec 2010
Total Posts: 17266
30 Dec 2013 02:53 PM
local char
while not player.Character do
char = player.CharacterAdded:wait()
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
30 Dec 2013 02:58 PM
char = plr.Character or plr.CharacterAdded:wait()
Report Abuse
triston220 is not online. triston220
Joined: 08 Mar 2010
Total Posts: 1861
30 Dec 2013 03:01 PM
Critique this:

Player.CharacterAdded:connect(function(Char)
repeat wait() until Player.Character
end)

That's what I had to resort to today. Unless the single wait() was enough?
Report Abuse
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
30 Dec 2013 03:02 PM
You guys don't seem to understand that the Character is rarely nil and sometimes, when the localscript first starts, the current player.Character is the last, now dead, character...
Report Abuse
OneTrueGodTheHolyCow is not online. OneTrueGodTheHolyCow
Joined: 24 Oct 2013
Total Posts: 9350
30 Dec 2013 03:07 PM
while not Player.Character or (Player.Character:FindFirstChild("Humanoid") and Player.Character.Humanoid.Health > 0) do wait(0) end
Report Abuse
Usering is online. Usering
Joined: 18 Aug 2012
Total Posts: 10281
30 Dec 2013 04:23 PM
Why not:

repeat wait() until player.Character
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
30 Dec 2013 04:50 PM
At least most scripts won't have to worry about me. Local scripts often load up 20+ seconds after my character. Unless it's a good day, then like 5 seconds after.
Report Abuse
Decompiler is not online. Decompiler
Joined: 30 Aug 2012
Total Posts: 1453
30 Dec 2013 08:03 PM
game.Workspace:WaitForChild(player.Name)

Could cause problems if something in the Workspace has the same name as the player.
Report Abuse
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
30 Dec 2013 09:46 PM
@Decompiler

Like the old, dead humanoid.
Report Abuse
RyanDolan123 is not online. RyanDolan123
Joined: 05 Mar 2009
Total Posts: 17919
31 Dec 2013 12:34 AM
>game.Workspace

._.
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