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: This is simple and works but is there a more efficient way?

Previous Thread :: Next Thread 
xLink123 is not online. 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 is not online. 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
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
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 is not online. 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
DeveloperBlue is not online. DeveloperBlue
Joined: 15 Apr 2009
Total Posts: 1344
23 Jul 2015 01:15 PM
loliderp's method is the most effecient
Report Abuse
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
23 Jul 2015 01:16 PM
Regardless its the same.
Report Abuse
DeveloperBlue is not online. DeveloperBlue
Joined: 15 Apr 2009
Total Posts: 1344
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 is not online. 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 is not online. 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
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
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
DeveloperBlue is not online. DeveloperBlue
Joined: 15 Apr 2009
Total Posts: 1344
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
DeveloperBlue is not online. DeveloperBlue
Joined: 15 Apr 2009
Total Posts: 1344
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 is not online. 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
DeveloperBlue is not online. DeveloperBlue
Joined: 15 Apr 2009
Total Posts: 1344
23 Jul 2015 01:38 PM
Sorry,

Just for the Model, not it's children.
Report Abuse
cntkillme is not online. 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 is not online. IoIiderp
Joined: 05 Feb 2012
Total Posts: 8613
23 Jul 2015 02:45 PM
@cntkillme
Okay then, what should I use?
Report Abuse
cntkillme is not online. 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 is not online. 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
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