Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Hey guys how do i kick a player when they get inside a brick or model?

Asked by 4 years ago

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

3 answers

Log in to vote
0
Answered by
KixWater 126
4 years ago
Edited 4 years ago

Try this and see if it works.

01--Server Script
02 
03local part = script.Parent --Change this to the location of the part
04local owner = game.CreatorId
05 
06-- Create a Remote Event and put it in Replicated Storage
07local RemoteEvent = game.ReplicatedStorage.RemoteEvent --Name this to the name of the remote event
08local DB = false -- Take this out if you don't want a cooldown
09 
10part.Touched:Connect(function(hit)
11    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
12    local hum = hit.Parent:FindFirstChild("Humanoid")
13    if not DB then
14        DB = true
15        if hum and plr.UserId = owner then
View all 42 lines...

If this doesn't work please tell me cause it is literally 2 AM right now and I can't think as well.

0
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. KixWater 126 — 4y
0
Hey, its ok but am new to like coding Lua ,oh and where do i put the serverscript and localscrpit in? Yodadthin 2 — 4y
Ad
Log in to vote
0
Answered by
uhjos_h 19
4 years ago
Edited 4 years ago

To make this, I would suggest using this method I am about to show.

1function onTouch(hit)
2    if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
3        kick = game.Players:FindFirstChild(hit.Parent.Name)
4        kick:Kick("specify reason here")
5    end
6end
7 
8script.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!

0
This is not what he asked. And you can find the player easier. KixWater 126 — 4y
Log in to vote
0
Answered by
ryanzhzh 128
2 years ago

why am i bringing up a old post.

1local ownerHitbox = script.Parent
2 
3local owner -- set this to the owner's name
4 
5ownerHitbox.Touched:Connect(function(hit)
6    if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent.Name == owner then
7        hit.Parent:PivotTo(hit.Parent:GetPivot() * CFrame.new(0, 0, -10))
8    end
9end)

Script, the part that you want to run code when touched.

Answer this question