Get HRP from Players or Workspace?

Hiwiwi :3
1- Is there differences between these 2 lines?

game.Players.Dev_Peashie.Character.HumanoidRootPart
game.Workspace.Dev_Peashie.HumanoidRootPart

2- Why when I access the HRP from Players Service I have to put Character before HumanoidRootPart?

3- Which one should I use? Is there a default approach for this?

Thank u for ur time

1 Like

The first line traverses through the list of players to access a part. The second goes through the workspace.

It’s generally better to go through the Players service to access a character, because you won’t need to worry about other things in the workspace sharing the same name as a player who has joined your game.

As for question 2, game.Players.Dev_Peashie is Player object, not a Model. Using .Character takes you to the model.

For q3, always go through Players to access a player by name.

4 Likes
  1. the 1st choice is more accurate. Such as, some creators have their avatar in game and this might select the in-game avatar instead of the player avatar. 2. you have to put Character because it is the name of what their character is called inside of their player. 3. as I mentioned for 1 the 1st choice would be better to use in general.
2 Likes

Your character doesn’t have to be in game.Workspace thats why you can access it from Player.Character which is a lot easier.

For example in my game I have a folder system for everything, so characters wouldn’t be directly in game.Workspace

3 Likes

Thank you so much, sounds very clear! Thank you u all guys @blobbyblob, @sniper74will, @RVVZ for make this clearer for me

1 Like

The API site is also a must have, it will answer many of your questions and even help you learn new things. Roblox Engine API Reference | Documentation - Roblox Creator Hub

This is the player reference: Player | Documentation - Roblox Creator Hub

If your question has been answered, make sure to mark a solution. And I also suggest having a more informative title for any other developers who share the same question to find.

1 Like