Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how would you make a script print a players name if the player is in game.Players?

Asked by 6 years ago

so i'm trying to make a custom admin panel and for a part of the script i'm doing is a warning script, you enter a players name and it warns the player. if you enter a player name and that player does not "exist" then it would display nothing. but if you enter a wrong player name then a error comes up and if you enter the right name it wont work :/ here is the script:

local PlayerName = script.Parent.Parent:WaitForChild("PlayerNameV") -- this is for what i'm writing later
local Reason = script.Parent.Parent:WaitForChild("ReasonV") -- same as above 
local Frame = script.Parent.Parent
local debounce = true

script.Parent.MouseButton1Click:Connect(function()
    if debounce == true then
        debounce = false
        if game.Players[Frame.PlayerName.Text] then
            print(Frame.PlayerName.Text)
        end
        wait(.2)
        debounce = true
    end
end)
0
You say you want 2 different things for: if you enter a name of a player that does not exist and if you enter an incorrect name, but both of these are the same. Please clarify. farrizbb 465 — 6y
0
Also you haven't said what is wrong with your code. farrizbb 465 — 6y
0
well what happens is when you enter something into a text box, then press a button, it checks if the text you entered in the text box is equal to a name in game.Players. if it is then it will print the players name. if there is no player that is equal to the text you put in the text box, then nothing will happen. The problem is that when you enter something into the text box and it does not equal cruizer_snowman 117 — 6y
0
a name in game.Players, a error pops up in the output and if you then try to enter a name that is correct, it wont work cruizer_snowman 117 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago
local frame = script.Parent.Parent
local reason = frame.Reason
local plrName = frame.PlayerName
--No debounce needed.

script.Parent.MouseButton1Click:Connect(function()
    if game:GetService("Players"):FindFirstChild(plrName.Text) then
        -- do code 
    else
        print"player not found!"
    end
end)
0
Thanks! cruizer_snowman 117 — 6y
Ad

Answer this question