Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script cant check if player exists?

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)

7 comments

0

And yes, i am using a TextBox.

0

are you using the correct case? Everything is case sensitive unless you make it more flexible

0

do you type the full players name

0

also please sne dthe output next time

0

There is no output, and the player's name is gotten by putting it in a textbox and saving it in a stringvalue.

0

alright

0

alright

2 answers

✓ Accepted answer
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
)

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

1 comment

0

yay~ nice job

This discussion is preserved as it was. New answers, comments, and votes are closed.