xLink123
|
  |
| Joined: 07 Aug 2014 |
| Total Posts: 11158 |
|
|
| 23 Jul 2015 01:11 PM |
I feel like somehow this could error some way
game.Workspace.ChildAdded:connect(function(child) if child:FindFirstChild("Humanoid") then child.Humanoid.WalkSpeed = 50 end end) |
|
|
| Report Abuse |
|
|
igunaa
|
  |
| Joined: 15 Sep 2010 |
| Total Posts: 2588 |
|
|
| 23 Jul 2015 01:13 PM |
I can`t find a way for it to error seriously.
Said the wise. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 01:13 PM |
Well a more efficient way would be to make it auto change the walkspeed on Respawn.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) local humanoid = Character:FindFirstChild("Humanoid") Humanoid.WalkSpeed = 50 end) end)
Something like that :)
|
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 23 Jul 2015 01:14 PM |
game:GetService("Players").PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(char) char:WaitForChild("Humanoid").WalkSpeed = 50 end) end) |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 01:15 PM |
| loliderp's method is the most effecient |
|
|
| Report Abuse |
|
|
| |
|
|
| 23 Jul 2015 01:22 PM |
| Well, not necessarily, loli's uses :WaitForChild("Humanoid"), while yours would just skip over it and error if it failed to load in time. |
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 23 Jul 2015 01:24 PM |
If you don't use my method the next post will be: This works in test mode but not online. |
|
|
| Report Abuse |
|
|
igunaa
|
  |
| Joined: 15 Sep 2010 |
| Total Posts: 2588 |
|
|
| 23 Jul 2015 01:25 PM |
@Dev xLink`s has it in .ChildAdded doesn`t he? Or ChildAdded work as for a Model inserted, not for all parts/stuff inside the model?
Said the wise. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 01:25 PM |
| If the character didn't load then the CharacterAdded event would not fire anyway because character would be nil also. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 01:29 PM |
@igunaa
The thing with Xlink's code is,
He's called .ChildAdded on Workspace,
Which means everything ANYTHING is added into Workspace, (Blocks, Models, Players, Bullets, Tools, Dropped Hats)
It will call that code. That's a "Brute Force" method.
The easier way is to, for each Player that joins, every time they create a Character, just set that new Character's health to 50.
So, instead of Xlink's
CHECK EVERYTHING FOR HUMANOID THEN SET IT which will run every single time something is added to workspace,
We can just have it run the check only when it's needed- when a new Character is created. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 01:30 PM |
@Dark
The thing is, maybe the "Model" Character will load, but the parts under it may not have loaded yet. Maybe only a few things have loaded, maybe nothing loaded, or maybe everything did load properly.
It's best to add :WaitForChild("Humanoid") to compensate for any lagg, rather than have it skip :FindFirstChild("Humanoid") because the Humanoid simply just didn't load before the line was called. |
|
|
| Report Abuse |
|
|
igunaa
|
  |
| Joined: 15 Sep 2010 |
| Total Posts: 2588 |
|
|
| 23 Jul 2015 01:33 PM |
@Dev, I`ve already gotten that, my question was: if you add a Model to the Workspace, the ChildAdded gets triggred, but does it get triggered for all the Model`s children or only once for the Model itself?
Said the wise. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 01:38 PM |
Sorry,
Just for the Model, not it's children. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Jul 2015 02:43 PM |
'loliderp's method is the most effecient' nope, creating a new function closure every time a player joins as opposed to just reusing the closure and defining the function outside. |
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 23 Jul 2015 02:45 PM |
@cntkillme Okay then, what should I use? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Jul 2015 02:47 PM |
Using yours is fine, what I'm saying is really just nitpicking.
But this is what I mean: local function changeWalkSpeed(char) char:WaitForChild("Humanoid").WalkSpeed = 50 end
game:GetService("Players").PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(changeWalkSpeed) end);
|
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 24 Jul 2015 04:20 AM |
Oh I see, well mine is easier to write out :) But indeed yours is more efficient even though the diffrence is really small. |
|
|
| Report Abuse |
|
|