Kick Gui button

So right now I am making this tool that tells you a players rank in group, acc age, username, and tools in backpack. You click on any player to get their info. I added a kick gui button. I am having trouble incorporating a code that if you click the kick button, it kicks the player you clicked on. Can you guys help? Here is my code:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local tool = script.Parent


local Frame = game.Players.LocalPlayer.PlayerGui:WaitForChild('ScannerGUI'):WaitForChild('Frame') --Object path to the GUI frame containing the age and rank textboxes.
local groupID = 4796549 --ID of your group.



tool.Equipped:Connect(function()
	Frame.Visible = true
	Frame.Parent.Backround.Visible = true
end)



tool.Activated:Connect(function()
	for _,Target in pairs(game.Players:GetPlayers()) do
		if Mouse.Target:IsDescendantOf(Target.Character) then
			Frame.AccAge.Text = Target.AccountAge
			Frame.RoleInGroup.Text = Target:GetRoleInGroup(groupID)
			Frame.AccName.Text = Target.Name
			local ToolsInBackpack = Target.Backpack:GetChildren()
			local listStr = ""
			Frame.Tools.Text = ""
			for i,v in pairs(ToolsInBackpack) do
				if v:IsA("Tool") then
					print(v.Name)
					Frame.Tools.Text = Frame.Tools.Text..v.Name.."\n"	
				end
			end
		end	
	end
end)





-- Make sure they can't use the tool while it is not selected.
tool.Unequipped:Connect(function()
	Frame.Visible = false
	Frame.Parent.Backround.Visible = false
end)

Thanks for reading.

4 Likes

just do

Target:kick()

(30 chr)

Yes but where? And what function do I do?

The server, just call it on the player during the OnServerEvent function, additionally, I recommend having a table that lets you know if the player is so you can check the player before kicking so they are actually allowed to use the Kick feature so it can’t be exploited.

Can you explain it more thoroughly? Can you write out the script for me and tell me where to put it?

I can’t feed code sorry.

Look for remote events and remote functions on dev wiki and player API

@romeanyguy10 I recommend you look at this.

Unfortunately, devforum is not the place to simply ask for scripts. You’ll never learn like that :slight_smile:. However, you can definitely make good use of the Developer Hub. You should take a look at the remote functions/events page.

So you need to use Mouse.Hit to detect a Player, and then fire a remote event that passes on the Player’s name to the Server, and then kick the Player

just do

local function OnActive(mouse)
    mouse.target:Kick("you have been kicked")
end)

Tool.Activated:Connect(OnActive)

You can kick from the client, makes no difference since with FE it only affects the LocalPlayer. In this case it would be on the server yes, but just so this guy doesnt get confused that is has to be on the server or something

So you’re going to try to kick another player on the client?

Insert objects
Text button: Under frame
Remote Event: Under Replicated Storage
Script: Under ServerScriptService

Local Script

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local tool = script.Parent

local Frame = Player.PlayerGui:WaitForChild("ScannerGUI").Frame 

--Object path to the GUI frame containing the age and rank textboxes.
local groupID = 4796549 --ID of your group.

tool.Equipped:Connect(function()
	Frame.Visible = true
	Frame.Parent.Backround.Visible = true
end)

tool.Activated:Connect(function()
	if Mouse.Target ~= nil and Mouse.Target.Parent:FindFirstChild("Humanoid") then
		local Target = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
		if Target then
			Frame.AccAge.Text = Target.AccountAge
			Frame.RoleInGroup.Text = Target:GetRoleInGroup(groupID)
			Frame.AccName.Text = Target.Name
			
			--!!! Made a button in frame!
			connect = Frame.KickButton.MouseButton1Click:Connect(function()
				if Target then
					--Added Remote Event! In replicated storage!
					game.ReplicatedStorage.Remote:FireServer(Target)
					
					-- Reseting!
					Frame.Visible = false
					Frame.Parent.Backround.Visible = false
					connect:Disconnect()
				end
			end)
			
			local ToolsInBackpack = Target.Backpack:GetChildren()
			local listStr = ""
			Frame.Tools.Text = ""
			for i,v in pairs(ToolsInBackpack) do
				if v:IsA("Tool") then
					print(v.Name)
					Frame.Tools.Text = Frame.Tools.Text..v.Name.."\n"	
				end
			end
		end	
	end
end)


-- Make sure they can't use the tool while it is not selected.
tool.Unequipped:Connect(function()
	Frame.Visible = false
	Frame.Parent.Backround.Visible = false
	for i,v in pairs(Frame:GetChildren) do
		if v:IsA("TextLabel") then v.Text = " "
	end
end)

Server script

local Remote = game.ReplicatedStorage.Remote

local PlayerThatCanKick = {10100010} -- UserId of players that can kick players
-- To find a players userid. Go to their profile page and look at the url.

Remote.OnServerEvent:Connect(function(plr,kickplayer)
	if plr and kickplayer then
		local isin = false
		for i,v in pairs(PlayerThatCanKick) do
			if v == plr.UserId then
				isin = true
			end
		end
		if isin == true then
			kickplayer:Kick("Bye Bye you have been kicked!")
		end
	end
end)

If it’s not working:
Remember that it’s UserIds and not Names.
The remote event needs to have the name “Remote”
The kick button need to have the name “KickButton”
Script needs to be in ServerScriptService.

but just so this guy doesnt get confused that is has to be on the server or something

Please read.

I understand now, your point was confusing to me since I am not sure what he’ll do with the knowledge that you can kick on the client even if you mean he can do it.