I have this prison game and it has a owner only room but i want it to make it kick a person when they get through the door or wall any help would be great and thank you also tell me where to put the script in and what type of script it is like a script or local script
Hey guys how do i kick a player when they get inside a brick or model?
3 answers
Try this and see if it works.
--Server Script
local part = script.Parent --Change this to the location of the part
local owner = game.CreatorId
-- Create a Remote Event and put it in Replicated Storage
local RemoteEvent = game.ReplicatedStorage.RemoteEvent --Name this to the name of the remote event
local DB = false -- Take this out if you don't want a cooldown
part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local hum = hit.Parent:FindFirstChild("Humanoid")
if not DB then
DB = true
if hum and plr.UserId = owner then
RemoteEvent:FireClient(plr)
else
plr:Kick("Name the Reason Of Kicking the Player Here!")
end
wait(3)
DB = false
end
end)
-- Local Script
local RemoteEvent = game.ReplicatedStorage.RemoteEvent --Name this to the name of the remote event
local part = script.Parent --Change this to the location of the part
RemoteEvent.OnClientEvent:Connect(function(plr)
part.CanCollide = false
part.Transparency = part.Transparency - 0.4
wait(3)
part.CanCollide = true
part.Transparency = part.Transparency + 0.4
end)
If this doesn't work please tell me cause it is literally 2 AM right now and I can't think as well.
To make this, I would suggest using this method I am about to show.
function onTouch(hit)
if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
kick = game.Players:FindFirstChild(hit.Parent.Name)
kick:Kick("specify reason here")
end
end
script.Parent.Touched:Connect(onTouch)
Basically, if a player touches a specific part- it will kick them. This is in a regular script, (not local).
How this works:
If a player hit the brick, it will kick them by using onTouch. Using onTouch will trigger an event, events is what actually calls the function - (best way to describe it) I would suggest looking at the DevForum, if you would like to learn more about events and functions!
There are also several other methods that I would suggest looking into, but this is the method that I personally prefer, and would use for a creation I made.
To set this up:
Create a regular script inside the part,
Type or paste in the following code.
If you have any questions, feel free to ask, I am willing to help!
1 comment
This is not what he asked. And you can find the player easier.
why am i bringing up a old post.
local ownerHitbox = script.Parent
local owner -- set this to the owner's name
ownerHitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent.Name == owner then
hit.Parent:PivotTo(hit.Parent:GetPivot() * CFrame.new(0, 0, -10))
end
end)
Script, the part that you want to run code when touched.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
I just realized you only wanted to kick them, not do anything else cause I added in where if the owner of the game touches the door, then the door opens and you can walk in. Sorry but im so tired right now.
Hey, its ok but am new to like coding Lua ,oh and where do i put the serverscript and localscrpit in?