Fire a function when a textbox.Text = Player.Name

Trying to make it so if you type a Player.Name into a textbox a function is called, for me, its not working…
image
“KOS” is the text box, as well as “ROS”

1 Like

you may need to move your for loop into a event connection. If you want it to work when the user writes text then try :GetPropertyChanged(“Text”) otherwise try .FocusLost like so


ROSText.FocusLost:Connect(function(enterPressed)
	if not enterPressed then
		return
	end
	
	for i, v in Players:GetPlayers() do
		if ROSText.Text == v.DisplayName then
			print("User pressed enter worked!")
		end
	end
end)

ROSText:GetPropertyChangedSignal("Text"):Connect(function()
	for i, v in Players:GetPlayers() do
		if ROSText.Text == v.DisplayName then
			print("User wrote text worked!")
		end
	end
end)
2 Likes

Do you know why when i add

if ROSText.Text == v.DisplayName or v.Name then
--code
end

it fires every time i type a letter and no matter if the name is right or not, when i press enter it prints

so the or statement doesn’t know anything about the ROSText.Text == part, it is only checking like if you wrote

if v.Name then

Which will always be true, since the player always has a name right? So you need to be explicit on both sides of the or like so

if ROSText.Text == v.DisplayName or ROSText.Text == v.Name then
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.