local char = script.Parent
function collisionGroupExists(name)
for _,v in pairs(game:GetService("PhysicsService"):GetCollisionGroups()) do
if v.name == name then
return true
end
end
return false
end
local PhysicsService = game:GetService("PhysicsService")
local zed = "WallGroup"
local map = "BallGroup"
if collisionGroupExists("WallGroup") == false then
PhysicsService:CreateCollisionGroup(zed)
end
if collisionGroupExists("BallGroup") == false then
PhysicsService:CreateCollisionGroup(map)
end
PhysicsService:CollisionGroupSetCollidable(zed, map, false)
function getchar()
for i,v in pairs(char:GetChildren())do
if v:IsA'BasePart' then
PhysicsService:SetPartCollisionGroup(v, zed)
elseif v:IsA'Model' or v:IsA'Hat' or v:IsA'Accoutrement' or v:IsA'Accessory' then
for i,e in pairs(v:GetChildren())do
if e:IsA'BasePart' then
PhysicsService:SetPartCollisionGroup(e, zed)
end
end
end
end
end
function getmap()
for i,v in pairs(workspace:GetChildren())do
if v ~= char then
if v:IsA'BasePart' then
PhysicsService:SetPartCollisionGroup(v, map)
elseif v:IsA'Model' and v ~= char or v:IsA'Hat' or v:IsA'Accoutrement' or v:IsA'Accessory' or v:IsA'Folder' then
for i,e in pairs(v:GetChildren())do
if e:IsA'BasePart' then
PhysicsService:SetPartCollisionGroup(e, map)
elseif e:IsA'Model' or v:IsA'Hat' or v:IsA'Accessory' then
for i,t in pairs(e:GetChildren())do
if e:IsA'BasePart' then
PhysicsService:SetPartCollisionGroup(t, map)
end
end
end
end
end
end
end
end
getmap()
getchar()
script:Destroy()
Check your console first before posting threads like this. If there was an error you would see it there. If there isn’t an error, then can you supply more information such as where specifically it doesn’t work? If you don’t know that either, then can you do some of your own debugging to isolate where the problem specifically happens at?
Can’t be dumping code with no information attached to the thread.
Well theres no error, the whole point of the code it to make the character not be able to collide with everything, however he collides with everything. Console has 0 errors.
So are you aware where specifically the code is dropping off then? What parts of your code are running as intended and what parts aren’t? Where is the issue specifically? That problem code needs to be isolated so we know what we’re looking for.
Thats the part I need help on. I’ve printed everywhere and it prints at every part. It definitely adds the parts to each respective collisiongroup. Yet I’ve no clue why it still collides.
If everything works and you can confirm that parts are added to their respective CollisionGroups but characters still collide, then you might have some leftover parts that were not added. Are you able to confirm if this was the case?
You typically need to account for added parts since not everything is guaranteed to be added when the character spawns in. CharacterAdded fires before the character is even constructed at all. Any leftover parts that are added later after you set groups can cause your system to fail.
By the way, for character, would be better to just use GetDescendants to get all parts.
for _, v in ipairs(char:GetDescendants()) do
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, zed)
end
end