daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Nov 17th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- no collision script by AquaSlicer
  2.  
  3. local PhysicsService = game:GetService("PhysicsService")
  4. local Players = game:GetService("Players")
  5.  
  6. local playerCollisionGroupName = "Players"
  7. PhysicsService:CreateCollisionGroup(playerCollisionGroupName)
  8. PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)
  9.  
  10. local previousCollisionGroups = {}
  11.  
  12. local function setCollisionGroup(object)
  13.   if object:IsA("BasePart") then
  14.     previousCollisionGroups[object] = object.CollisionGroupId
  15.     PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
  16.   end
  17. end
  18.  
  19. local function setCollisionGroupRecursive(object)
  20.   setCollisionGroup(object)
  21.  
  22.   for _, child in ipairs(object:GetChildren()) do
  23.     setCollisionGroupRecursive(child)
  24.   end
  25. end
  26.  
  27. local function resetCollisionGroup(object)
  28.   local previousCollisionGroupId = previousCollisionGroups[object]
  29.   if not previousCollisionGroupId then return end
  30.  
  31.   local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
  32.   if not previousCollisionGroupName then return end
  33.  
  34.   PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
  35.   previousCollisionGroups[object] = nil
  36. end
  37.  
  38. local function onCharacterAdded(character)
  39.   setCollisionGroupRecursive(character)
  40.  
  41.   character.DescendantAdded:Connect(setCollisionGroup)
  42.   character.DescendantRemoving:Connect(resetCollisionGroup)
  43. end
  44.  
  45. local function onPlayerAdded(player)
  46.   player.CharacterAdded:Connect(onCharacterAdded)
  47. end
  48.  
  49. Players.PlayerAdded:Connect(onPlayerAdded)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top