I’m trying to make it so that you need he minimum rank required to not collide with it. For example, members collide with it, but admins don’t. Script below:
local PhysicsService = game:GetService("PhysicsService")
local doorcollisiongroup = "OnStage"
PhysicsService:CreateCollisionGroup(doorcollisiongroup)
PhysicsService:CollisionGroupSetCollidable(doorcollisiongroup, doorcollisiongroup, false)
PhysicsService:SetPartCollisionGroup(workspace.OnStage, doorcollisiongroup)
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if Player:GetRankInGroup(9963063) >= 252 then
for _,v in pairs(Character:GetDescendants()) do
if v:IsA("Part") then
PhysicsService:SetPartCollisionGroup(v, doorcollisiongroup)
end
end
end
end)
end)
local Trap = script.Parent
local GroupId = 9963063
local MinRank = 253
local function OnTouch(Object)
local Player = game.Players:GetPlayerFromCharacter(Object.Parent)
if Player then
if Player:GetRankInGroup(GroupId) < MinRank then
Object.Parent.HumanoidRootPart.CFrame = game.Workspace.NotStaffTP.CFrame
end
end
end
Trap.Touched:Connect(OnTouch)
You should use two collision groups. Otherwise the Admins can also walk through each other.
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local AdminDoor = workspace.example -- Whatever code you use to get the door instance
local doorCollisionGroup = "OnStage"
local adminCollisionGroup = "Admin"
local GroupId = 9963063 -- The group ID of the group you want to use
local MinimumGroupRank = 252 -- The minimum rank you must be in the group to be able to walk through the door
PhysicsService:CreateCollisionGroup(doorCollisionGroup)
PhysicsService:CreateCollisionGroup(adminCollisionGroup)
PhysicsService:CollisionGroupSetCollidable(doorCollisionGroup, adminCollisionGroup, false)
PhysicsService:SetPartCollisionGroup(AdminDoor, doorCollisionGroup)
Players.PlayerAdded:Connect(function(player)
local isAdmin = (player:GetRankInGroup(GroupId) >= MinimumGroupRank)
local connect
connect = player.CharacterAdded:Connect(function(character)
if isAdmin then
for _,child in ipairs(character:GetChildren()) do
if child:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(child, adminCollisionGroup)
end
end
else
connect:Disconnect()
end
end)
end)
NOTE:
Because Player:GetRankInGroup caches it’s results the player will have to rejoin the game if they join the group while in-game. That is why we have and isAdmin variable and disconnect the connect variable if the isAdmin variable is false. There would be no point in checking further after the first time.