How to make a teleport button for specific player

Hello!

So i have a frame that a rank in a group can see, which duplicates a button for one for every player in the game. That part is work well, but the following script, to make the actual button work, does not.

What it is supposed to do is to teleport the player that has the name same as the text value on the button to a partivular position.

local t = Vector3.new(129.099, -134.792, 140.913) -- Teleport To
local plName = script.Parent.Text
local p = game.Players:FindFirstChild(plName)

script.Parent.MouseButton1Click:Connect(function()
	for i = 1, #p do 
		p[i].Character:MoveTo(t) 
	end
end)

This here is where the script is and where is formatted. The script button is parented to called ‘main’ duplicates the button for each player.

Help is much appreciated! I am sorry for grammar mistakes, i am still learning english.

I am sorry for the time gap -

  1. Yes, I took the value of a part i placed at the spot to teleport to and copied the position.
  2. A player, so the button is cloned for every player, so it would look like this (with the UIlist)
    player1
    player2
    player3

if the person with the gui clicked for example ‘Player2’ button, the script would need to find player2 and teleport them to the spot.

i was thinking to do it maybe by looking for the character model, since it dose not be named by a players display name

is this giving any errors in the output?

the Character’s just a property of the player, not an object. also, a for loop being used in this context doesn’t make much sense. i like your thinking though.

Instead, you should set the CFrame or Position of the character’s HumanoidRootPart.

1 Like

try this instead.

local t = Vector3.new(129.099, -134.792, 140.913) -- Teleport To
local plName = script.Parent.Text
local p = game.Players:FindFirstChild(plName)

script.Parent.MouseButton1Click:Connect(function(plr)
	plr.Character.HumanoidRootPart.Position = t
end)
1 Like
local Players = game:GetService("Players")

local function GetPlayerByDisplayName(DisplayName)
	for _, Player in ipairs(Players:GetPlayers()) do
		if Player.DisplayName == DisplayName then
			return Player
		end
	end
end

local Player = GetPlayerByDisplayName("") --Searched player's display name here.

Here’s a fairly simple script which will locate a player instance via their display name, be warned however, display names aren’t unique (can be shared between players) and as such the results could be ambiguous.