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
Try this and see if it works.
01 | --Server Script |
02 |
03 | local part = script.Parent --Change this to the location of the part |
04 | local owner = game.CreatorId |
05 |
06 | -- Create a Remote Event and put it in Replicated Storage |
07 | local RemoteEvent = game.ReplicatedStorage.RemoteEvent --Name this to the name of the remote event |
08 | local DB = false -- Take this out if you don't want a cooldown |
09 |
10 | part.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 |
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.
1 | function 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 |
6 | end |
7 |
8 | 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!
why am i bringing up a old post.
1 | local ownerHitbox = script.Parent |
2 |
3 | local owner -- set this to the owner's name |
4 |
5 | ownerHitbox.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 |
9 | end ) |
Script, the part that you want to run code when touched.