Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't my Collision Groups Script to make my player run into other players not Working?

Asked by 4 years ago
Edited 4 years ago

Here is my code:

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer

local PlayersInServer = "PlayersInServer"
local You = "You"

PhysicsService:CreateCollisionGroup(PlayersInServer)
PhysicsService:CreateCollisionGroup(You)

PhysicsService:SetPartCollisionGroup(Players, PlayersInServer)
PhysicsService:SetPartCollisionGroup(Player, You)

PhysicsService:CollisionGroupSetCollidable(PlayersInServer, You, false)

The code is supposed to let your player walk through other players. But not other things. I ran it in the editor to see if there are any errors in the code, and believe it or not, there was error. the error read,

14:03:05.045 - Parameter 1 must be BasePart in SetPartCollisionGroup.

It is a normal script. And it is also in the ServerScriptService.

I don't know what I did wrong. I know where to look, but I don't know what to do. Please help. Thank you.

0
I do not think the line "local You = "You" is valid. ghxstlvty 133 — 4y
0
How come? User#29793 0 — 4y

1 answer

Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
4 years ago

you could use this: Script inside ServerScriptService

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)

Source:https://developer.roblox.com/en-us/articles/Player-Player-Collisions

Ad

Answer this question