Basically I have an admin panel that uses a textbox to find the targeted user but I didn’t want the admin to have to type in the full exact name so I implemented a function to make it short but its not working. Can you help fix my script? No errors are outputed just doesnt work.
Code:
local kick = script.Parent.Frame:WaitForChild("Kick")
local warn1 = script.Parent.Frame:WaitForChild("Warn")
local ban = script.Parent.Frame:WaitForChild("Serverban")
local username = script.Parent.Frame:WaitForChild("user")
local kickremote = game:GetService("ReplicatedStorage").Events.Kick
local warnremote = game:GetService("ReplicatedStorage").Events.Warn
local serverbanremote = game:GetService('ReplicatedStorage').Events.Serverban
local function getUsername(text)
for i,v in ipairs(game.Players:GetPlayers()) do -- Goes through all the players
if string.find(string.lower(v.Name), string.lower(text)) then
return v -- Returns the player
end
end
return false -- This returns if nothing above is found
end
kick.MouseButton1Down:Connect(function()
kickremote:FireServer(getUsername(username.Text))
end)
warn1.MouseButton1Down:Connect(function()
warnremote:FireServer(getUsername(username.Text))
end)
ban.MouseButton1Down:Connect(function()
serverbanremote:FireServer(getUsername(username.Text))
wait()
kickremote:FireServer(getUsername)(username.Text)
end)
function check(name, wanted)
local plrname = string.split(name:lower(), "")
local wantedpart = string.split(wanted:lower(), "")
local possible = true
for i,v in pairs(wantedpart) do
local namepart = plrname[i]
if v ~= namepart then
possible = false
end
end
if possible then
return true
else
return false
end
end
to check the name of the player in question and whether it matches the name given or not. Here is an example of how to use it
function check(name, wanted)
local plrname = string.split(name:lower(), "")
local wantedpart = string.split(wanted:lower(), "")
local possible = true
for i,v in pairs(wantedpart) do
local namepart = plrname[i]
if v ~= namepart then
possible = false
end
end
if possible then
return true
else
return false
end
end
for i,v in pairs(game.Players:GetPlayers()) do
local ifpossible = possible(v.Name, username.Text)
if ifpossible then
print(v.Name)
end
end
no, I did this for a reason. I would not want to just match a string and get multiple players if their name just has that part in it. string.find just looks for a pattern inside of a string while my function checks whether their name (starting from the start of it) is equal to what is wanted. Here is an example of what I mean:
local players = {"sniper74will", "boysniper"}
for i,v in pairs(players) do
if string.find(v.Name, "sni") then
print(v.Name) --prints sniper74will and boysniper
end
end
yes, there may be other arguments, but the number init just tells where to START searching for the pattern. Here is a sentence taken directly from here:
string.find() Looks for the first match of pattern in the string s.
That’s exactly what you said. Also, if you don’t want to print both users just add a break statement.
By the way, your function doesn’t have where to END.