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

Why cant I compare the name of a different player with this search bar?

It's a simple GUI that im using to search for players. If a player's name is correct it will continue with the script. If it's not it will fail. I've been thinking o how to compare the names in the game.Players to my textbox.text. Anyone know how I could do this. Here is my code.

--This script runs the player editor execution.
--Made by Proo34

--Get Service Vaiables
local Players = game:GetService("Players")

--Variables
local playerfind = script.Parent.Main:WaitForChild("Search")
local playerName =script.Parent.Main:WaitForChild("SearchBar")

--Set
findplayer = 0
GUIRank = 0


--Main Player Graber
script.Parent.Main.Search.MouseButton1Click:Connect(function()
	if script.Parent.Main.SearchBar.Text == "" then
		print("No Player Searched")
		findplayer = 1
	else
		print("Looking for Player with name ".. script.Parent.Main.SearchBar.Text)
			
		local playerEditSearch = script.Parent.Main.SearchBar.Text
		findplayer = 2
	end
	
	if findplayer == 2 then
		
		if script.Parent.Main.SearchBar.Text == game.Players.LocalPlayer.name then
			GUIRank = 1
			print("Local player displayed")
			script.Parent.GUIChanger.Value = 1
		else
			
		--here is where the search needs to look for players who aren't local player
		--should be able to access all players
			
		end
		
	else
		print("Canceling Search")
		script.Parent.GUIChanger.Value = 0
	end
	
end)

1 answer

✓ Accepted answer

This goes through every player and determines if there name is exactly the same as the textbox [meaning it should repeat the same amount of times as there are players in the game] , im not sure if it would work if you just copy and pasted it because i don't know what your gui looks like. This isn't really a good way to find something it mean you have to type a name letter per letter. If you were to do something like this you look into the string.find() i don't know anything about it but it can be used for search engines i think.

btw im hardcore illiterate im sorry

local Players = game:GetService("Players")
local main = script.Parent.Main
local Search = main:WaitForChild("Search")
local SearchBar = main:WaitForChild("SearchBar")

Search.MouseButton1Click:Connect(function()
	for i,v in pairs(game.Players:GetChildren()) do
		if tostring(v.Name) == tostring(SearchBar.Text) then
			print('found player: '..v.Name)
			--add more code here
		else
			print('didn\'t find player: '..v.Name)
		end
	end
end)


1 comment

0

Thank you so much! This really helps me!

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