and I made this script inside the red kick button.
local kickButton = script.Parent
local plrNameBox = script.Parent.Parent.playerName
local reasonBox = script.Parent.Parent.Reasson
local players = game.Players
kickButton.MouseButton1Down:Connect(function()
players:WaitForChild(plrNameBox.Text):Kick(reasonBox.Text)
game.SoundService.menuClick:Play()
end)
It works fine, but you must type the player name correctly. How can I make it so it does not matter if you type it in capital or small letters?
You put the input into lowercase and then check like this but also lower the player’s name:
local kickButton = script.Parent
local plrNameBox = script.Parent.Parent.playerName
local reasonBox = script.Parent.Parent.Reasson
local players = game.Players
kickButton.MouseButton1Down:Connect(function()
players:WaitForChild(plrNameBox.Text:lower()):Kick(reasonBox.Text)
game.SoundService.menuClick:Play()
end)
local kickButton = script.Parent
local plrNameBox = script.Parent.Parent.playerName
local reasonBox = script.Parent.Parent.Reasson
local players = game.Players
kickButton.MouseButton1Down:Connect(function()
players:WaitForChild(plrNameBox.Text.string.lower()):Kick(reasonBox.Text)
game.SoundService.menuClick:Play()
end)
Loop through the players, lower their names and then check if that lowered version of their username matches the plrNameBox text. If it does, you kick them.
how do I do it that’s the problem I don’t know how???
local kickButton = script.Parent
local plrNameBox = script.Parent.Parent.playerName
local reasonBox = script.Parent.Parent.Reasson
local players = game.Players
kickButton.MouseButton1Down:Connect(function()
players.Name:lower(plrNameBox.Text):Kick(reasonBox.Text);
game.SoundService.menuClick:Play()
end)
local Players = game:GetService("Players")
local UserToKick = --string reference here
for _, player in ipairs(Players:GetPlayers()) do
local LoweredUser = player.Name:lower()
local LoweredText = UserToKick:lower()
if LoweredText == LoweredUser then player:Kick() end
end
To be honest, now that I think about it, I think there might be another option if you want to check if the input is close to the user’s name, it can be done with some math.
Would you like to enter a few letters of the player’s name and use a best-fit function to find the correct player?
Personally, I have found a small function script that works well, and I use it in all of my projects that involve finding players’ names.
local function get_best_target(target_name)
for _, player in pairs(game.Players:GetPlayers()) do
if (player.Name:lower():find(target_name) == 1) then
print('Best match is: ', player.Name)
return player
end
end
end
local kickButton = script.Parent
local plrNameBox = script.Parent.Parent.playerName
local reasonBox = script.Parent.Parent.Reasson
local players = game.Players
local playerTable = {}
kickButton.MouseButton1Down:Connect(function()
table.clear(playerTable)
for i, v in players:GetPlayers() do
table.insert(playerTable, string.lower(v.Name))
end
local plr = players:FindFirstChild(string.lower(plrNameBox.Text))
if table.find(playerTable, plr.Name) then
players:WaitForChild(plrNameBox.Text):Kick(reasonBox.Text)
game.SoundService.menuClick:Play()
else
print("Cannot find player")
end
end)
local kickButton = script.Parent
local plrNameBox = script.Parent.Parent.playerName
local reasonBox = script.Parent.Parent.Reasson
local players = game.Players
kickButton.MouseButton1Down:Connect(function()
players:WaitForChild(plrNameBox.Text):Kick(reasonBox.Text)
game.SoundService.menuClick:Play()
end)
As I can see from your script, the script is located inside the KickButton.
Setup:
Create a LocalScript inside of KickButton.
In the LocalScript place the following code:
Code:
local kickButton = script.Parent
local plrNameBox = script.Parent.Parent.playerName
local reasonBox = script.Parent.Parent.Reasson -- Here, make sure you actually have a TextBox named "Reasson" or fix the typo to "Reason".
local function get_best_target(target_name)
for _, player in pairs(game.Players:GetPlayers()) do
if (player.Name:lower():find(target_name) == 1) then
print('Best match is: ', player.Name)
return player
end
end
end
kickButton.MouseButton1Click:Connect(function()
local plr = get_best_target(plrNameBox.Text)
if plr then
plr:Kick(reasonBox.Text)
game.SoundService.menuClick:Play()
end
end)