Group rank collision groups not working

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)

I’ve been trying to solve this for a day now

if v:IsA("Part") then

change this to

if v:IsA("BasePart") then
1 Like

I tried that, but still nothing

if v:IsA("BasePart")  or v:IsA("MeshPart") v:IsA("UnionOperation") then

since some hats might be mesh parts

Error: Expected ‘then’ when parsing if statement, got ‘v’

if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation") then

forgot an or

So, no matter if I have the part’s cancollide set to true or false, anyone can still walk through it

(Fixed it!)

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.

1 Like