I’m trying to make a kick part of a GUI. It’s rather simple, once a TextBox’s focus is lost, it finds the closest player in the server matching the input, fires an event, and kicks them. However, it only works on the person who is the person kicking, and will not kick anybody else. Could I get some help?
Local script:
local textBox = script.Parent.Input
local players = game.Players
local event = game.ReplicatedStorage.PrivateServerGUIEvents.Kick
function input(e)
if e then
if textBox.Text:len() >= 4 then
local possiblePlayers = {}
for i, v in pairs(game.Players:GetChildren()) do
if string.find(string.lower(v.Name), string.lower(textBox.Text)) then
table.insert(possiblePlayers, i, v)
end
end
if #possiblePlayers == 1 then
event:FireServer(possiblePlayers)
end
end
end
end
textBox.FocusLost:Connect(input)
Server script:
local event = game.ReplicatedStorage.PrivateServerGUIEvents.Kick
function kick(p, t)
for i, v in pairs(t) do
v:Kick("You were kicked by the private server owner.")
end
end
event.OnServerEvent:Connect(kick)
The local script is under a GUI in StarterGui, the event is in a folder in ReplicatedStorage, and the server script is in a folder in ServerScriptService.
script.Parent.playername.FocusLost:Connect(function() ---your textbox
local text = script.Parent.playername.Text:lower() --textbox text
for i, v in pairs(game.Players:GetPlayers()) do
if string.sub(text,1,text:len()) == string.sub(v.Name:lower(),1,text:len()) then
local foundplr = v
game.ReplicatedStorage.PrivateServerGUIEvents:FireServer(foundplr)
end
end
end)
ServerScript:
local event = game.ReplicatedStorage.PrivateServerGUIEvents
event.OnServerEvent:Connect(function(player,t)
t:Kick("kicked")
end)