How I can make kick button

obraz_2023-02-25_222912376

My script:

script.Parent.MouseButton1Click:Connect(function(plr)
plr:Kick()
end)

Why this dont work?

4 Likes

The event doesn’t have a player argument.

3 Likes

image

Im new on forum i dont know what type is it

1 Like

Use the LocalPlayer property of the Players service to kick the player.

https://create.roblox.com/docs/reference/engine/classes/Players

1 Like

client sided can be bypassed by exploiters in game.StarterGui…

1 Like

I would do:
Even though you should try do more with the
code because of security in my opinion…

Local Script (Inside of a Button…)

local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")

local player = players.LocalPlayer
local event = replicatedStorage.RemoteEvent
local button = script.Parent

button.MouseButton1Click:Connect(function()
	local table = {
		Action = "KickSelf", 
		Message = "You kicked yourself using a remote event!",
	}
	event:FireServer(table)
end)

Server Script (Inside of ServerScriptService)

local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")

local event = replicatedStorage.RemoteEvent

event.OnServerEvent:Connect(function(player, table)
	if table.Action == "KickSelf" then
		player:Kick(table.Message)
	end
end)
3 Likes

Its because you are running it inside a local script

1 Like

Thats not necessary. You don’t need an argument in :Kick()

1 Like

It is optional, but displays a message to the player being kicked.

2 Likes

Yes, its optional but won’t affect whether or not the function works

1 Like

I said: the mousebutton1click event does NOT have a player argument.

1 Like

It does have a player argument? Its defined as “plr”.

1 Like

It does not,
image

1 Like

If I am not mistaken, that is not called a player argument. Thats a regular argument

1 Like

and also

script.Parent.MouseButton1Click:Connect(function()

print("test")

end)

works

1 Like

i don’t know what is a regular argument.

1 Like

Parameters are typed inside the () that comes after a function’s name.

They look like this:

local function FunctionName(parameterName) 
    parameterName += 20 -- adding 20 onto the number..
end)

local number = 5
FunctionName(number)

The actual information that gets passed through the parameter is called an argument.

1 Like

It didn’t work because there is no player
This is the script with player (local script)

script.Parent.MouseButton1Click:Connect(function()
game.Players.LocalPlayer:Kick("You decided to leave the game.")
end)

Thank you so much!!! Now it work!