How do you get Humanoid Root Part from a textbutton?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make the player when they click the text button it teleports them to a specific location using vector 3 or Cframe
  2. What is the issue? Include screenshots / videos if possible!
    The issue is how do you get the humanoid root part from a mouse click.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub
    i have tried looking it up but I had no luck.

You can teleport on the client, so you know the local player is Players.LocalPlayer, from there get the Character then the PrimaryPart, which is the humanoid root part.

1 Like

But wouldn’t you need to do that from a server script?How would you teleport a player using a local script?

The same way you would with a server script. Clients have network ownership over their character – take advantage of that.

1 Like

Im not sure what you exactly mean would you further explain? Would I need to use remote events

You can check if the player clicked on a local script - then fire a RemoteEvent and teleport the player from a Server Script.

Wait would that be a client to server remote event or server to client one to get the Humanoid root part.

Client to server, since you have to detect the click.

1 Like

incapaz was saying that you can do this entirely on the Client without needing RemoteEvents. From my understanding, this is because when a Client has Network Ownership over something (which in this case is their Character), the physics of that Instance will be calculated on the Client.

An example can be found below and more information on Network Ownership can be found on this Developer Hub article:

local Players = game:GetService("Players") -- References Players service
local player = Players.LocalPlayer -- References the LocalPlayer/the Client that has this LocalScript

local Character = player.Character or player.CharacterAdded:Wait() -- References the player's Character or waits for it to load into the game

local TextButton = script.Parent -- References the TextButton as "script.Parent"/the instance containing the LocalScript

TextButton.Activated:Connect(function() -- Whenever the button is clicked, it'll activate a function
    if Character and Character.PrimaryPart then -- If the Character exists and it has a PrimaryPart
        Character:SetPrimaryPartCFrame(CFrame.new(X,Y,Z)) -- Change X,Y, and Z to the new coordinates
        --[[ We can then teleport the Character to a new location 
        by setting the CFrame of its PrimaryPart to new coordinates, 
        as defined by X, Y, and Z --]]
    end -- Ends the "if Character and Character.PrimaryPart then" statement
end) -- Ends the TextButton.Activated function
1 Like

Thank you I have never actually heard of primarypartcframe which is actually why I was confused on that part but I now understand.

1 Like

No problemo! If you’d like to read more about :SetPrimaryPartCFrame(), you can check out this Developer Hub Article.

1 Like