What makes the Player object 50938 script.Parents?


  • I see lots of code that get the Player object like this:

    Player = script.Parent.Parent.Parent.Parent.Parent.Parent

    What is it parented to to get the player like that, and why?


  • @incapaz

    Imagine you've got a GUI. The GUI is inside PlayerGui, a frame is inside the GUI, another one is there, then you've got an ImageLabel, a TextButton, a LocalScript and inside the LocalScript another LocalScript that needs to access the Player.

    The best thing to access it is
    game.Players.LocalPlayer

    But people (like me) have a lot of imagination and use
    script.Parent.Parent.Parent.Parent.Parent...

    Going through all those Frames until it gets to the player.


  • @Aimarekin kind of dumb. whose idea was this. i use game:GetService("Players").LocalPlayer to get the player anyways so


  • Is this forum really designed for insulting beginners?


  • My best guess is for tools, that's the easiest way to know who owns the tool. (As the second parent of a tool is always the player unless putted in a folder (tools are int he backpack and the parent of the backpack is the player)
    EDIT: Of course, only for the server as you can use localplayer for the client.


  • @Phlegethon5778 a beginner's mistake would be using LocalPlayer on the server.

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.