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

Script cant check if player exists?

Asked by 4 years ago

I tried this, when the player doesn't exist, it prints that the player doesn't exist, but when the player does exist, it also prints that the player does not exist, how could i fix this?

local text = script.Parent.Text
local Players = game:GetService("Players")
script.Parent.FocusLost:Connect(function(enterPressed)
        if enterPressed then
            if not Players:FindFirstChild(text) then
                print("Player "..script.Parent.Text.." does not exist.")
            return end
            else
        print(script.Parent.Text)
        script.Parent.name.Value = script.Parent.Text
        script.Parent.Visible = false
        script.Parent.Parent.valueedit.Visible = true
    end
end)

0
And yes, i am using a TextBox. WatsPlayzROBLOX 80 — 4y
0
are you using the correct case? Everything is case sensitive unless you make it more flexible zadobyte 692 — 4y
0
do you type the full players name raid6n 2196 — 4y
0
also please sne dthe output next time raid6n 2196 — 4y
View all comments (3 more)
0
There is no output, and the player's name is gotten by putting it in a textbox and saving it in a stringvalue. WatsPlayzROBLOX 80 — 4y
0
alright raid6n 2196 — 4y
0
alright raid6n 2196 — 4y

2 answers

Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
local Players = game:GetService("Players")
script.Parent.FocusLost:Connect(
    function(enterPressed)
        if enterPressed then
            local text = script.Parent
            for _, player in pairs(Players:GetPlayers()) do
                if not text.Text == player.Name then
                    print("Player " .. script.Parent.Text .. " does not exist.")
                    return
                else
                    print(script.Parent.Text)
                    script.Parent.name.Value = script.Parent.Text
                    script.Parent.Visible = false
                    script.Parent.Parent.valueedit.Visible = true
                end
            end
        end
    end
)

Ad
Log in to vote
1
Answered by 4 years ago

Figured it out guys, had to put local text = script.Parent.Text after the focus lost.

0
yay~ nice job raid6n 2196 — 4y

Answer this question