As I can see from your script, the script is located inside the KickButton.
Setup:
- Create a
LocalScriptinside ofKickButton. - In the
LocalScriptplace 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!