How do i make it so your kick from a game when you touch a part

i want to make a part kick you from the game when you touch it. i tried thi article Player | Roblox Creator Documentation but it didnt really help. can someone please help?

1 Like

I mean just create a remoteevent, have the parameters store a variable for the player’s data in Players, and fire that from a localscript using the Touched event?

Touched is an event of BasePart (Parts, WedgeParts, etc) that returns a BasePart that hit the connected part, you can use the parent of that basepart to get the player via Players:GetPlayerFromCharacter(), which will return a player instance if the player’s character is the model given or nil. Then you can kick them

Example

local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if not player then
        return
    end
    player:Kick() --You can put a string in the brackets for a kickreason
end)

The order works like so

  • Something triggered the event, let’s check if the parent of it is a player character
  • If it finds that is belongs to a player, it returns the player, otherwise it returns nil
  • If it returned nil, don’t continue, if it returned a player instance, kick the player
5 Likes