Kick Player GUI

Hey guys, I made this menu.

image

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?

2 Likes

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)

Use string.lower() on both the player input and searched player names.

3 Likes

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:WaitForChild(plrNameBox.Text.string.lower()):Kick(reasonBox.Text)
	game.SoundService.menuClick:Play()
end)
1 Like

I would approach it like this:

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)
1 Like

Here’s an example:

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
1 Like

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.

1 Like

nothing works, for now, Idk what they mean.

1 Like

Pretty sure it does, you haven’t just integrated this code into your game.

1 Like

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

Hope that helps you out!

1 Like
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)
1 Like

How can I combine this script with my script

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)
2 Likes

As I can see from your script, the script is located inside the KickButton.


Setup:

  1. Create a LocalScript inside of KickButton.
  2. 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)

Hope this helps you!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.