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
What is the issue?
Everything works,
The problem is that its can only find the local player
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)
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
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.