Leg collisions are not right

I’m trying to turn off player collisions for my game.


As you can see I made the players leg long. Now the problem with the leg is that the leg is still colliding with the player even though I turned off player collisions. I have tried asking people on many discord servers and no one could help

  • Player collisions off script in SSS
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

local playerCollisionGroupName = "Players"
PhysicsService:CreateCollisionGroup(playerCollisionGroupName)
PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)

local previousCollisionGroups = {}

local function setCollisionGroup(object)
	if object:IsA("BasePart") or object:IsA("MeshPart") or object:IsA("Part") then
		previousCollisionGroups[object] = object.CollisionGroupId
		PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
		print(object.Name)
	end
end

local function setCollisionGroupRecursive(object)
	setCollisionGroup(object)

	for _, child in ipairs(object:GetDescendants()) do
		setCollisionGroupRecursive(child)
	end
end

local function resetCollisionGroup(object)
	local previousCollisionGroupId = previousCollisionGroups[object]
	if not previousCollisionGroupId then return end 

	local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
	if not previousCollisionGroupName then return end

	PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
	previousCollisionGroups[object] = nil
end

local function onCharacterAdded(character)
	setCollisionGroupRecursive(character)

	character.DescendantAdded:Connect(setCollisionGroup)
	character.DescendantRemoving:Connect(resetCollisionGroup)
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)
  • Leg script in StarterCharacterScripts
local char = script.Parent

char["Right Leg"]:Destroy()
local leg = Instance.new("Part")
leg.Name = "RightLeg"
leg.Parent = char
char:WaitForChild("Torso")["Right Hip"].Part1 = leg
leg.Position = leg.Position - Vector3.new(0,4.95,0)
leg.Size = Vector3.new(1,12,1)
leg.Reflectance = 0.1
leg.Material = Enum.Material.SmoothPlastic

Wdym colliding with the player? You mean it’s colliding with your own character or others?

It’s somewhat to be expected since the new leg you’re adding is CanCollide, whereas by default the legs aren’t CanCollide anyways (The Humanoid controls “leg” collisions, which is why you can float with a larger HipHeight, and still walk.)

The leg is colliding with other peoples’ leg. If that makes sense.

That would be due to it being CanCollide. Once again, you shouldn’t have legs with CanCollide on. The humanoid handles your legs unless they get deleted which effectively makes your HipHeight 0.

Well, this isn’t the actual leg. It’s a part welded to the character, so it shouldn’t act like a “normal” leg. It’s basically if you attached a part to the character.

Okay okay you’re just not going to listen to the main point.

Anyways, you’re not exactly doing collision groups correctly anyways.

Let me write out some code and I’ll get back to you with an edit.

Edit:
Server Code:

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

-- Setup collision groups
do
  Physics:CreateCollisionGroup("General")
  Physics:CreateCollisionGroup("LocalCharacter")
  Physics:CollisionGroupSetCollidable("General", "LocalCharacter", false)
end

-- Define Cache for clean up later
local Connections = {}

-- Define auxiliary handlers
local function CharAdded(Character)
  task.wait(0.075) -- Wait for a small moment to ensure Character is loaded.
  for _, Part in pairs(Character:GetDescendants()) do
    if (Part:IsA("BasePart") or Part:IsA("MeshPart") or Part:IsA("Part")) then
      Physics:SetPartCollisionGroup(Part, "General")
    end
  end
  task.defer(function()
    local NoCollisions = Character:FindFirstChild("NoCollisions")
    if NoCollisions then
      NoCollisions.Disabled = false
    end
  end)
end

-- Define primary handlers
local function Connected(Player)
  Connections[Player.UserId] = Player.CharacterAdded:Connect(CharAdded)
end

local function Disconnected(Player)
  if Connections[Player.UserId] then
    pcall(function() Connections[Player.UserId]:Disconnect() end)
  end
end


-- Connect primary handlers
Players.PlayerAdded:Connect(Connected)
Players.PlayerRemoving:Connect(Disconnected)

NoCollisions (StarterCharacterScripts LocalScript, Disabled = true):

-- NoCollisions localscript
local Players = game:GetService("Players")
local Physics = game:GetService("PhysicsService")

local Client = Players.LocalPlayer

local Character = Client.Character or script.Parent

-- Do the basic stuff first
for _, Part in pairs(Character:GetDescendants()) do
  if (Part:IsA("BasePart") or Part:IsA("MeshPart") or Part:IsA("Part")) then
    Physics:SetPartCollisionGroup(Part, "LocalCharacter")
  end
end

-- More handlers... yay...
local function SetCollisions(Descendant)
  if (Descendant:IsA("BasePart") or Descendant:IsA("MeshPart") or Descendant:IsA("Part")) then
    Physics:SetPartCollisionGroup(Descendant, "LocalCharacter")
  end
end

local function RemoveCollisions(Descendant)
  if (Descendant:IsA("BasePart") or Descendant:IsA("MeshPart") or Descendant:IsA("Part")) then
    Physics:SetPartCollisionGroup(Descendant, "Default")
  end
end

Character.DescendantAdded:Connect(SetCollisions)
Character.DescendantRemoving:Connect(RemoveCollisions)

There you go, try out the code I’ve posted on my last post’s edit.

Somehow still the legs are colliding, and also its getting me stuck in the floor?
image

local PhysicsService = game:GetService("PhysicsService")
local NoclipPart = "NoclipPart"
local RightLeg = "RightLeg"

local debounce = false

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		char:WaitForChild("RightLeg")

		for i,v in pairs(workspace:GetDescendants()) do
			if v.Name == "NoclipPart" then
				PhysicsService:SetPartCollisionGroup(v, NoclipPart)
			end
		end
		
		PhysicsService:SetPartCollisionGroup(player.Character.RightLeg, RightLeg)
		PhysicsService:CollisionGroupSetCollidable(RightLeg, NoclipPart, false)	
	end)
end)

Forgot to add this. Its so I can walk on the platform normally. I guess the script you sent got mixed up with this.

1 Like