So, I'm making a team based game and decided to make team only doors (Doors that only people on the respective team can use) using the new Collision group. I'm a very new scripter, so to try to understand the concept I followed the ROBLOX wiki example listed in the announcement blog post

The following is all the code from that tutorial for sake of comparison

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
 
local redForceField = game.Workspace.RedStartingZone.ForceField
local blueForceField = game.Workspace.BlueStartingZone.ForceField
 
local redForceFields = "RedForceFields"
local blueForceFields = "BlueForceFields"
local redPlayers = "RedPlayers"
local bluePlayers = "BluePlayers"
 
PhysicsService:CreateCollisionGroup(redForceFields)
PhysicsService:CreateCollisionGroup(blueForceFields)
 
PhysicsService:CreateCollisionGroup(redPlayers)
PhysicsService:CreateCollisionGroup(bluePlayers)
 
PhysicsService:SetPartCollisionGroup(redForceField, redForceFields)
PhysicsService:SetPartCollisionGroup(blueForceField, blueForceFields)
 
PhysicsService:CollisionGroupSetCollidable(redForceFields, redPlayers, false)
PhysicsService:CollisionGroupSetCollidable(blueForceFields, bluePlayers, false)
 
local function setCollisionGroupRecursive(object, groupName)
	if object:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(object, groupName)
	end
	for _, child in ipairs(object:GetChildren()) do
		setCollisionGroupRecursive(child, groupName)
	end
end
 
local function onCharacterAdded(character, team)
	local collisionGroupName = team.Name .. "Players"
	setCollisionGroupRecursive(character, collisionGroupName)
end
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(character)
		onCharacterAdded(character, player.Team)
	end)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)

Now I looked over the script for awhile and I'm pretty sure I understand it for the most part. So, I'm pretty sure the things I should change for it to work in my place would be this part:

local redForceField = game.Workspace.RedStartingZone.ForceField
local blueForceField = game.Workspace.BlueStartingZone.ForceField

Also although not needed, changing the following would be the goal, as in the future my teams' names won't be Red and Blue, of course, to test it out I don't care as I just want it to work, so, I have team names simply "Red" And "Blue"

local redPlayers = "RedPlayers"
local bluePlayers = "BluePlayers"

so I tweaked that first part to be

local redForceField = game.Workspace.Rspawnbuilding.RSpawnDoor1 -- I changed this to my team door
local blueForceField = game.Workspace.sy.NeonTbrick -- just a random part cause i dont have a blue base yet, 
--still should work as there still is a blue team and the part is valid

Since It still wasn't working, I decided to add debugging help using print() (note I'm not 100% sure if the print text is the correct terms to be using, but either way, I thought it would indicate at something)

So, the edited code is:

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
 
local redForceField = game.Workspace.Rspawnbuilding.RSpawnDoor1 -- I changed this to my team door
local blueForceField = game.Workspace.sy.NeonTbrick -- just a random part cause I don't have a blue base yet, 
--still, should work as there still is a blue team

local redForceFields = "RedForceFields"
local blueForceFields = "BlueForceFields"
local redPlayers = "RedPlayers"
local bluePlayers = "BluePlayers"
 
PhysicsService:CreateCollisionGroup(redForceFields)
PhysicsService:CreateCollisionGroup(blueForceFields)
 
PhysicsService:CreateCollisionGroup(redPlayers)
PhysicsService:CreateCollisionGroup(bluePlayers)
 
PhysicsService:SetPartCollisionGroup(redForceField, redForceFields)
PhysicsService:SetPartCollisionGroup(blueForceField, blueForceFields)
 
PhysicsService:CollisionGroupSetCollidable(redForceFields, redPlayers, false)
PhysicsService:CollisionGroupSetCollidable(blueForceFields, bluePlayers, false)
 
local function setCollisionGroupRecursive(object, groupName)
	print("checking for basepart for")
	print(object)
	if object:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(object, groupName)
		print("Yes it is a base part")
		print("________")
	else
		print("No it's not a base part")
		print("________")
	end
	
	for _, child in ipairs(object:GetChildren()) do
		print("~~~~~~~~~~~~~~")
		print("adding child:")
		print(child)
		print(groupName)
		print("~~~~~~~~~~~~~~")
		setCollisionGroupRecursive(child, groupName)
	end
	print("Done with set")
end
 
local function onCharacterAdded(character, team)
	print("players team is")
	print(team)
	local collisionGroupName = team.Name .. "Players"
	setCollisionGroupRecursive(character, collisionGroupName)
end
 
local function onPlayerAdded(player)
	print("phase 1 player added")
	player.CharacterAdded:Connect(function(character)
		onCharacterAdded(character, player.Team)
		print("Character Added start")
	end)
end


 
Players.PlayerAdded:Connect(onPlayerAdded)

If you want the output log, I'll add that, but since It's kinda long, and I don't want to make this question any longer, I won't post it yet.

Since it might be prudent, ill post the behavior properties of the spawn door (In studio, not in-game)

Anchored = true
Archivable = true
CanCollide = true
CollisionGroupId = 0
Locked = false

So, in the end, I concluded that the tutorial must have had the flawed code, is that true, or did I just overlook something. And either way, What would i have to change for it to work?

3 comments

0

If the output has errors, you should include them.

0

There's no error messages in the output unfortunately.

0

I have the same problem.