Hello Developers,
I am having trouble with this kicking Gui. I have an autofill script for a name input. If I have no text in the name input it kicks me no matter what but if I choose a different player it kicks them. I don’t understand why it’s kicking me though? Anyone know why or how this is happening? Or how to fix it?
Client Script
local function getPlayerFromPartialName(PartialName)
local foundName = nil
local Players = game.Players:GetPlayers()
for i = 1, #Players do
local PossiblePlayer = Players[i]
if string.find(string.lower(PossiblePlayer.Name), string.lower(PartialName)) then
foundName = PossiblePlayer.Name
end
end
if not foundName then
return nil
else
return foundName
end
end
script.Parent.ScrollingFrame:WaitForChild("Kick").Activated:Connect(function()
local KickingName = getPlayerFromPartialName(script.Parent.Autofill.Text)
game.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = KickingName.." has been kicked from the session.",
Font = Enum.Font.GothamSemibold,
FontSize = Enum.FontSize.Size96,
})
print(script.Parent.Autofill.Text)
print(KickingName)
game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("KickEvent"):FireServer(KickingName)
end)
Server Script
local function getPlayerFromPartialName(PartialName)
local foundName = nil
local Players = game.Players:GetPlayers()
for i = 1, #Players do
local PossiblePlayer = Players[i]
if string.find(string.lower(PossiblePlayer.Name), string.lower(PartialName)) then
foundName = PossiblePlayer.Name
end
end
if not foundName then
return nil
else
return foundName
end
end
KickEvent.OnServerEvent:Connect(function(player, KickingName)
local PlayerToKick = getPlayerFromPartialName(KickingName)
print(player.Name.." is Kicking "..PlayerToKick)
game.Players:FindFirstChild(PlayerToKick):Kick("You have been kicked from the game.")
end)