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?

01local text = script.Parent.Text
02local Players = game:GetService("Players")
03script.Parent.FocusLost:Connect(function(enterPressed)
04        if enterPressed then
05            if not Players:FindFirstChild(text) then
06                print("Player "..script.Parent.Text.." does not exist.")
07            return end
08            else
09        print(script.Parent.Text)
10        script.Parent.name.Value = script.Parent.Text
11        script.Parent.Visible = false
12        script.Parent.Parent.valueedit.Visible = true
13    end
14end)
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
01local Players = game:GetService("Players")
02script.Parent.FocusLost:Connect(
03    function(enterPressed)
04        if enterPressed then
05            local text = script.Parent
06            for _, player in pairs(Players:GetPlayers()) do
07                if not text.Text == player.Name then
08                    print("Player " .. script.Parent.Text .. " does not exist.")
09                    return
10                else
11                    print(script.Parent.Text)
12                    script.Parent.name.Value = script.Parent.Text
13                    script.Parent.Visible = false
14                    script.Parent.Parent.valueedit.Visible = true
15                end
16            end
17        end
18    end
19)
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