CanCollide on player's parts on the client isn't working

Hi, I am trying to make the player a ghost, but the player can’t go through other players who are still “alive.” I tried setting CanCollide = false but that isn’t working. Here is my code:

for _, players in pairs(game.Players:GetPlayers()) do
					for c, part in pairs(v.Character:GetChildren()) do
						if part:IsA("MeshPart") then
							part.CanCollide = false
						end
						if part:IsA("Accessory") then
							part.Handle.CanCollide = false
						end
						if part:IsA("Part") and part.Name ~= "HumanoidRootPart" then
							part.CanCollide = false
						end
					end
				end

Is this a Typo or a mistake?
You have players defined in your in pairs loop.
In the script, you use the variable part, which isn’t defined where we can see it.

You need this script:

local Physics = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local Group = "Players"

Physics:CreateCollisionGroup(Group)
Physics:CollisionGroupSetCollidable(Group,Group, false)

function CollisionGroup(Obj,G)
    if Obj:IsA("BasePart") then
        Physics:SetPartCollisionGroup(Obj,G)
    end
end

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Wait()
    for i,Obj in pairs(Player.Character:GetDescendants()) do
        CollisionGroup(Obj,Group)
    end
    Player.Character.DescendantAdded:Connect(function(Obj)
        CollisionGroup(Obj,Group)
    end)
end)

Put it in ServerScriptService.

That didn’t seem to work. Here is my code:

Touched Script:

script.Parent.Touched:Connect(function(person)
	if game.Players:GetPlayerFromCharacter(person.Parent) then
		local player = game.Players:GetPlayerFromCharacter(person.Parent)
		if game.ReplicatedStorage.Values.GameInProgress.Value == true then
			if not player:FindFirstChild("Murderer") or not player:FindFirstChild("Sheriff") or not player:FindFirstChild("Innocent") then
				
				game.ReplicatedStorage.Events.CreateCollisionGroup:Fire(player)
			end
		end
	end
end)

Event Handling:


local Physics = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local Group = "Players"

Physics:CreateCollisionGroup(Group)
Physics:CollisionGroupSetCollidable(Group,Group, false)

function CollisionGroup(Obj,G)
	if Obj:IsA("BasePart") then
		Physics:SetPartCollisionGroup(Obj,G)
	end
end

game.ReplicatedStorage.Events.CreateCollisionGroup.Event:Connect(function(Player)
	for i,Obj in pairs(Player.Character:GetDescendants()) do
		CollisionGroup(Obj,Group)
	end
	Player.Character.DescendantAdded:Connect(function(Obj)
		CollisionGroup(Obj,Group)
	end)
end)

These both are scripts

Sorry, I already understood xd

local Physics = game:GetService("PhysicsService")
local Group1 = "Alive"
local Group2 = "Ghost"

Physics:CreateCollisionGroup(Group1)
Physics:CreateCollisionGroup(Group2)
Physics:CollisionGroupSetCollidable(Group1,Group2, false)

function CollisionGroup(Obj,G)
    if Obj:IsA("BasePart") then
	    Physics:SetPartCollisionGroup(Obj,G)
	end
end
function Player_Alive(Player)
    for i,Obj in pairs(Player.Character:GetDescendants()) do
    	CollisionGroup(Obj,Group1)
    end
    Player.Character.DescendantAdded:Connect(function(Obj)
	    CollisionGroup(Obj,Group1)
    end)
end
function Player_Ghost(Player)
    for i,Obj in pairs(Player.Character:GetDescendants()) do
	    CollisionGroup(Obj,Group2)
	end
    Player.Character.DescendantAdded:Connect(function(Obj)
	    CollisionGroup(Obj,Group2)
    end)
end

It only remains to call the function.

1 Like