So I'm trying to make a GUI where you type in the players name you would like to teleport but so far nothing happens when I do so. The script is located in a button. I am sure I have got my player directly targeted.
playerselect = script.Parent.Parent.PlayerSelect.Text script.Parent.MouseButton1Down:connect(function() local choose = script.Parent.Parent:FindFirstChild(playerselect.Text) for i,v in pairs(game.Players:GetChildren()) do if v.Name == choose then local target = v.Character.Torso.Position script.Parent.Parent.Parent.Parent.Parent.Parent.Character.Torso.Position = CFrame.new(target) end end end)
I notice a few errors with this.
The first might not be an issue, but it looks suspicious: is the TextBox PlayerSelect
or Text
? If it's PlayerSelect
, then the line should be this:
playerselect = script.Parent.Parent.PlayerSelect
Next, the for
loop is probably not necessary, since there will only be up to one player with the name specified. You can achieve the same effect with this:
local player = game.Players:FindFirstChild(playerselect.Text) if player then -- Rest of code here. end
Finally, you're trying to set the Position
of the character (a Vector3 value) to a CFrame. Since this won't work, you should do this instead:
local target = player.Character.Torso.CFrame -- The long .Parent chain is not necessary; note that this requires a local script to work. game.Players.LocalPlayer.Character.Torso.CFrame = target
The complete code should look like this:
playerselect = script.Parent.Parent.PlayerSelect script.Parent.MouseButton1Down:connect(function() local player = game.Players:FindFirstChild(playerselect.Text) if player then local target = player.Character.Torso.CFrame game.Players.LocalPlayer.Character.Torso.CFrame = target end end)