Staff Only Area

Hi, so I am trying to make it so if a Customer for my game enters the staff only area they die.
The brick is set to no collision and I’m not sure how to get it to work.

Any help would be appreciated :slight_smile:.


I would recommend using Collision Groups, which you can find under the Model tab.
Through scripts you could set the player’s collision group (default, or staff) and staff will not have collision with the door while regular players will. This way you don’t have to kill a player who is trying to go through the door but it is still staff only.

EDIT: You put the player’s character into the collision group, just to clarify.

1 Like

I have set up some collision groups now, what else do I do? Ty for the advice.

1 Like

There is a property of parts called “CollisionGroupId”. When a staff spawns their CollisionGroupId should be set to Staff. Also, you want to make sure staff do not have collision with the door by unchecking the box where they intersect like so.
You can also set parts into a collision group in studio by selecting it and clicking the plus on the collision groups editor, so you should do that with the door to put it in that collision group

this probably really stupid but I’ve never really used collision groups, where do I get the id from? I have my two groups set up.

Would probably be good to use method fungibot mentioned, but if it’s too complicated to you then you can just follow advices above.
Firstly, if i’m not mistaking if you don’t put objectTouched(as you defined in function) under if statement then it will check EVERY player in the game, since it’s local script. So every non staff member would die(if script worked obviously).
Second, you don’t need to put end at the end of your code. You already did it for function, and it doesn’t makes sense to put end at the end of event.
Third, please always put local before defining variable, unless you need to make variable inside function be defined outside of it. I’m refering to line 2 and line 3 of your code.
After you apply first two errors I mentioned script would work, but since it’s local script exploiters can easily delete this script and it will never run on their part, thus gaining them access to staff area. For that reason I advise you to use collision group as fungibot mentioned. Hope you will set it up properly and it would work for your game!

Edit: Mistake objectTouched with player, that you defined at the start of the script. You need to put player under if statement, not objectTouched, since objectTouched returns part of the player that touched part, not LocalPlayer itself

1 Like

I don’t know if there’s a better way but you could go in studio and add a part to a collision group, see what the ID is, and then remove the part. If you remember what order you added them in the one you added first probably has the ID 1.

Also one last thing how would I change a players collision group to staff? And thank you for your help!

--Hopefully this helps!
local character
local parts = character:GetChildren()

for _,i in pairs(parts) do
    if i.ClassName == "Part" or i.ClassName == "MeshPart" then
    	i.CollisionGroupId = 1 -- Or whatever the ID of the group is

After reading through your script, I noticed one thing.

It says Trap.Touched:Connect(onTouch) inside of the function.

This will not work, if you want to call it, put it outside the function underneath.

You should add a wall with collision near the staff area, and then a kill area inside of the staff room. Here’s why.

Exploiters can use noclip, but they can’t give themselves godmode. If they do intend on using noclip, that extra space inside of the room will prevent them from entering.

Pretty simple no need to overcomplicate things. Simply do player:GetRankInGroup(YourGroupIdHere) .

local Player = game.Players:GetPlayerFromCharacter(hit.Parent) – Gets the player
local Rank = player:GetRankInGroup(YourGroupID) – Gets the player’s rank in the group
if Rank == “Customer” then
hit.Parent:BreakJoints() – Kill Player

Rank returns a string value which shows their role in the group, so don’t compare it to a number. Hit is the parameter ObjectTouched in your function. Also, you can’t access localplayer in server scripts.

As @DankDinoDragon there’s no need for collisions group in this.

I would advise having a kill or kick script still even if you make it closed off to non staff. The reason being that hackers can easily bypass collision groups, and a kill or kick script would add a layer of protection to that area

This is a LocalScript right? LocalScripts in parts don’t work, so you’ll have to convert it to a script, then define the player like: local player = game.Players:GetPlayerFromCharacter(objectTouched.Parent)
Also you’re connecting the function inside of the function which won’t work. Move it to below it.

This should work.
local Trap = script.Parent
local GroupId = 8202832
local MinRank = 3

local function OnTouch(Object)
local Player = game.Players:GetPlayerFromCharacter(Object.Parent)
if Player then
if Player:GetRankInGroup(GroupId) < MinRank then



Does the part have to have collisions turned on?

No it doesn’t. Extra words because limit

Thank you so much! Your the only person who has made it work :slight_smile:

1 Like