Not Able To Get Player Name

Helo, im trying to make a TP admin ui. I have a textbox where you right the player name in and then theyll get teleported to you. I am using a script. Im trying to get player but the output is there is no player named (your name). I think I might not be doing it right OR it needs to be done in a local script. Please help thanks SCRIPT:

2 Likes

To check if the player exists all you have to do is check if their name is in Players.

Confirm.MouseButton1Up:Connect(function()
   local player = game.Players:FindFirstChild(Box.Text)
   if player then
      print("Player Found")
    else
      print("not found")
   end
end
2 Likes

Try this:

local Confirm = script.Parent.Frame.Censor
local Box = script.Parent.Back.TextBox

Confirm.MouseButton1Up:Connect(function()
        if #Box.Text > 3 then
           local Player
           for _,Plr in ipairs(game.Players:GetChildren()) do
            if string.sub(Plr.Name:lower(),1,#Box.Tect) == string.lower(Box.Text) then
                     Player = Plr
                     break
             end
     end
    if Player then
           print("Player Found!")
    end
end)
PlayerName = game.Players:GetFullName(Box.Text)
if PlayerName ~= nil then
print("Player")
else
print("Not found")
end

You should be always localizing your variables. GetFullName doesn’t take any arguments. Players:GetFullName() Always returns “game.Players”

This still doesn’t work it says my name is not found

Confirm.MouseButton1Up:Connect(function()
   local player = game.Players[Box.Text] 
   if player then
      print("Player has been found.")
    else
      print("Not in-game.")
   end
end

Is it an script or an local script?

It should be a local script. Server scripts aren’t working on GUIs.

1 Like

This is a Script…

This would be in the same LocalScript it was in before. Also, do game.Players:FindFirstChild(Box.Text) instead of game.Players[Box.Text] or else your code may erorr when the player does not exist.

Use an local script. Server scripts are for server-side, not client-side.

1 Like

It should be a local script. Please, change it. Also, my script makes you only to say instead of YumReesesPuffs only Yum

1 Like

So if I use a Local Script will it still teleport the players name?

Nevermind.
Yeah, you can still teleport them by local script, as on the server it will still show their player position.

1 Like

Use remote events.

-- Local Script in Button

local confirm = script.Parent.Frame.Censor
local Box = script.Parent.Back.TextBox

local rep = game:GetService("ReplicatedStorage")
local new = rep:WaitForChild("TPEvent")

local player = game.Players.LocalPlayer

Confirm.MouseButton1Up:Connect(function()
	new:FireServer(Box.Text)
end)

-- Script in ServerScriptService

local new = Instance.new("RemoteEvent")
new.Parent = game.ReplicatedStorage
new.Name = "TPEvent"

local function teleport(player, text)
	for i,v in pairs(game.Players:GetChildren()) do
		if v.Name == text then
			player.Character.HumanoidRootPart.CFrame = v.Character.HumanoidRootPart.CFrame + Vector3.new(2, 0, 0)
		end
	end)
end

new.OnServerEvent:Connect(teleport)

Might have messed up on my ends there.

1 Like

I like how you said only 3 words but this isent working for me

Can you show us the Explorer where you put the local script? I don’t think you made what we said.