How to make a tool kick the player who used it

I want a tool that is supposed to be meant for a joke and when they use it I want it to play a animation then kick them, How do I make it kick them?


local player = game.Players:GetPlayerFromCharacter(onActivation)
local tool = script.Parent
tool.Parent = game.Players.LocalPlayer.Backpack

function onActivation()
	print("Tool activated")
	
	player:Kick("log") 
	
	
end

tool.Activated:Connect(onActivation)

This is what i have but it won’t work

can you make sure the player isn’t nil? can you make the script print the player variable. also did you get any errors?

Just tested your script. the player is nil.

i did just make my own rendition and it works fine, you may have to edit a few things.

tool = script.Parent.Parent -- where the tool is
tool.Activated:Connect(function()
	local char = script.Parent.Parent.Parent -- Where the character is. When the tool is equipped, the tool is in the character's model.
	print(char) -- confirming by printing the character's name. if this is nil / doesn't print then the character wasn't found.
	local plr = game.Players:GetPlayerFromCharacter(char) -- gets the player.
	plr:Kick("Begone") -- kicks player.
end)

@snobW0lf hope this helps!

100% guaranteed to work. Put this in a server Script.

local tool = script.Parent
local Players = game:GetService("Players")
tool.Activated:Connect(function()
    local char = tool.Parent
    local plr = Players:GetPlayerFromCharacter(char)
    if plr then
        plr:Kick("log")
    end
end)
1 Like

I don’t understand your code.

local player = game.Players:GetPlayerFromCharacter(onActivation)

This is wrong - functions aren’t player characters?! Set it to game.Players.LocalPlayer but only if you are using a LocalScript.

1 Like

First off, to kick a player. You must have a player var
to get a player. You must have a char or a plr var of it selfs
When player equip a tool, it goes to a characters so we can get a id

local plr = nil
tool.Equipped:Connect(function()
if plr == nil then
local char = script.Parent
plr = game.Player:GetPlayerFromCharacter(char)
end
end)

Now the activation just simple and i think you can do it

I am well aware of how you kick a player. Clearly, you didn’t understand what I meant.

My point was, his statement “game.Players:GetPlayerFromCharacter(onActivation)” does not make sense because he is trying to get a player from a function, rather than a character. Obviously, it will return nil because functions aren’t characters.

I agree with you since his script didnt make sense.

Tool.Activated (roblox.com)
this article sure that he doesnt understand with it. Remember that a activated is only a event and it doesnt give any parameters

GetPlayerFromCharacter actually does exist if you didn’t know.

I don’t recall denying its existence. I was saying that onActivation is not a character and therefore passing it into GetPlayerFromCharacter will never return a player since functions are not characters.

Please read what I say properly before making unfounded comments. I say this not because I intend to be hostile towards you or anyone else, but to express my frustration with these easily avoidable misinterpretations.

My apologizes if I sounded hostile. I just wanted to let you know in case you didn’t, since you didn’t state whether you did or not. Other than that you are correct.

No, I was apologising in advance for potentially sounding hostile in my most recent message. You weren’t hostile at all.


I didn’t explicitly specify whether I knew the function existed or not because it’s implied that I know it exists, just that it will never work the way it should so long as an invalid argument is passed.

1 Like

This should work in a local script:


local player = game.Players.LocalPlayer
local tool = script.Parent
tool.Parent = game.Players.LocalPlayer.Backpack

function onActivation()
	print("Tool activated")
	
	player:Kick("log") 
	
	
end

tool.Activated:Connect(onActivation)