Kick Button - TextBox

Hello! So I wanted to add a feature where if a player adds a name into a TextBox, and the text in the TextBox is a player in the lobby, and if the player clicks a button, it will click the player whose name is in the TextBox. However, it doesn’t work and the Developer Consle says nothing.

Script:
script.Parent.MouseButton1Click:Connect(function(clicked)
local PlayerNameInTextBox = script.Parent.Parent:WaitForChild(“TextBox”).Text
local Player = game.Players.PlayerAdded:Connect(function(Player)
if clicked then
if PlayerNameInTextBox == Player.Name then
Player:Kick(“Access Expired - Commander©️ | Making Roblox Better”)
end
end
end)
end)

1 Like

is it in a local script or server script

LocalScript. Should it be in a Server Script?

No. You need both. Use a local script to fire a remote event into the server and then kick the play from the server

1 Like

For security reasons, a ServerScript should be used. As for the current code, I believe the issue is the PlayerAdded function, since it ends at line 9, meaning that anything inside of it will not be ran.

Oh, ok. So I need to change the PlayerAdded function just to local Player = game.Players.LocalPlayer ?

Yes, that is correct, but there must also be other changes. I found a post which is similar to yours and might help.

Create a remote event in replicated storage called RemoteEvent

--local script
script.Parent.MouseButton1Click:Connect(function(clicked)
    local PlayerNameInTextBox = script.Parent.Parent:WaitForChild(“TextBox”).Text
    local Player = game.Players.LocalPlayer
    if PlayerNameInTextBox == Player.Name then
        game.ReplicatedStorage.RemoteEvent:FireServer()
    end
    
end)
--server script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    player:Kick(“Access Expired - Commander©️ | Making Roblox Better”)
end)

If it did work, it would be appreciated if you set it as solution :slight_smile:

2 Likes

Thank you so much! Have a great Day/Night! <3

1 Like

You should use a remote event In order to kick the player, try this:

LocalScript:

local event = script.Parent.RemoteEvent --or wherever It is :d

script.Parent.MouseButton1Click:Connect(function()

local PlayerNameInTextBox = script.Parent.Parent:WaitForChild(“TextBox”).Text
local Player = game.Players:FindFirstChild(PlayerNameInTextBox)
if Player then
event:FireServer(Player)
end
end)

(Server) Script:

local event = script.Parent.RemoteEvent

event.OnServerEvent:Connect(function(LocalPlayer, Player)
Player:Kick("Reason.")
end)

I’m kinda late, because I’m a slow typer on the phone :sweat_smile:
but still, hope I could help!

That’s totally fine! I found a solution already, but thank you so much for the help! Have a fantastic Day/Night! <3

1 Like

it works, but only when you want to kick yourself, but when you want to kick someone else, then it won’t work anymore

1 Like