CanTouch Property For Player?

So let’s just say that I want to make CanTouch false for all players. Is there a way to do this? If so, how exactly can I do this?

This script disables collisions for all players.

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") then
    previousCollisionGroups[object] = object.CollisionGroupId
    PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
  end
end
 
local function setCollisionGroupRecursive(object)
  setCollisionGroup(object)
 
  for _, child in ipairs(object:GetChildren()) 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)

This script disables player collisions, but does not make CanTouch false for all players. So how exactly would I make CanTouch false for all players using a script? Is this even possible?

Also I am referring to the CanTouch property and not the CanCollide property. This post should explain the difference between the two properties.

1 Like

…You should be able to just set the property to false in all the limbs, yeah?

1 Like

So I can go to the StarterCharacter and set CanTouch to false there?

1 Like

Ohh I see, the following code should do what you’re looking for (and you could definitely combine this with your other script!!)

game.Players.PlayerAdded:Connect(function(plr)
 plr.CharacterAdded:Connect(function(character)
  for _,Limb in character:GetChildren() do
   if Limb:IsA("BasePart") then
    Limb.CanTouch = false
   end
  end
 end
end)

Try this:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		for i, v in pairs(char:GetChildren()) do
			if v:IsA("BasePart") then
				v.CanTouch = false
			end
		end
	end)
end)

--ServerScript BTW
1 Like

that is exactly what i was thinking, :frowning: you won

1 Like

There was just one difference xd…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.