Does the client can see other players?

  1. What do you want to achieve?

So, i am trying to make a system that when you enter a username it will automatically find it for you even if the capitalization is’nt correct or the username is’nt finished
ex: bEe > Beez_up

  1. What is the issue?
    Everything works,
    The problem is that its can only find the local player

  2. What solutions have you tried so far?
    i don’t know

This is a local script in StarterGui

-- Made By Beez_up for Honeyz Cafe
-- Module
local module = require(script.Parent.Configuration)
-- Variables
local gui = script.Parent
local frame = gui.UserName
local enter = frame.Enter
local close = frame.Close
local answer = frame.Answer.TextBox
local plrtogive = nil
--____________________________--
-- Functions
local function smartfinder(username)
	tostring(username)
	string.lower(username)
	for _,v in pairs(game.Players:GetPlayers()) do
		if string.find(string.lower(v.Name),username) then
			print("Found")
			return v
		else
				return nil
		end
	end
end
local function close_order()
	
end
--____________________________--
-- Events
enter.MouseButton1Down:Connect(function()
	-- Logics
	if not module.smartfinder then
		if game.Players:FindFirstChild(answer.Text) then
			plrtogive = answer.Text
			elseif answer.Text == '' or answer.Text == ' ' then
				answer.Text = "Enter UserName Here!"
		else
				answer.Text = answer.Text .. "not found!"
		end
	else
			local plrfound = smartfinder(string.lower(answer.Text))
			if plrfound ~= nil then
				plrtogive = plrfound.Name
				answer.Text =  plrfound.Name .. "has been found."
		else
				print("no one has been found")
			end
	end
end)

Thank you :smiley:

I think it may be that clients can’t see any other players inside game.Players, but I can’t remember for sure.

Use remote events or remote functions.

Also, if you try to pass a player entity directly with a remote event/function, the client still may not be able to see the passed in player entity.

To answer your question, yes, the client can see the other players connected to the game.

Next, tostring and string.lower return an edited string, they don’t reassign any variables.

Lastly, I’ve had this kind of problem before. Here’s I function a wrote to get you the first player that matches a string (if any):

local function FindUser(String)
	for _, Player in next, game:GetService("Players"):GetPlayers() do
		if string.match(string.lower(Player.Name), string.lower(tostring(String))) then
			return Player
		end
	end
	
	return nil
end

Hope this helps!

So i tried to do it but the client can’t see the players connected in game.
So i will try it with a RemoteFunction

Can you elaborate on what you mean? For me, I can see the other connected clients using game:GetService("Players"):GetPlayers().

Character Models replicate, the Player Object does not.

To make things inside the Player Object replicate, look at remote events

For ultimate clarification!

Yes the client can search for and find all players in the server with game:GetService('Players'):GetPlayers()

Note that not all the children/ elements of the player object can be seen by other clients; such as playerGUI. Also note that the player object doesn’t replicate from client to server; but it does from server to client (like most things). And LocalPlayer is a pointer to your player object, but it itself is not a player object and is not replicatable at all.

Conclusion!
The issue you were having was that the smartfinder function would enter a loop to check all players, but it would never take a second iteration.

If the first player checked was who you were looking for then it would return that player, otherwise it would return nil. So toss away that else statement. And use username=string.lower(username), so that username gets updated to its lowercase beauty.

1 Like