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

An Easier Way For Collision Groups? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

Hello everyone! Another question from me! :D

Today I was testing Roblox's collision groups feature, and it didn't work. :P I've made many attempts with it, and I just can't get it to work. First, it errored saying it couldn't create a group, now it says it can't create more than 32 groups. I don't quite understand this feature. :P

This's the code I've been using:

local PhysicsService = game:GetService('PhysicsService')
local pl = Workspace:WaitForChild('PLACE') -- A square-ish box with an open door
local fig = Workspace:WaitForChild('TEST_FIGURE') -- A fake player

function Parts(obj)
    local parts = {}
    for i, v in next, obj:GetChildren() do
        if v:IsA('BasePart') then
            table.insert(parts, v)
        end
    end
    return parts
end

local num = 0; local num2 = 0
for i, v in next, pl:GetChildren() do
    print(num, 'PLACE') -- Stops at 12
    for i2, v2 in next, Parts(fig) do
        print(num2, 'FIGURE') -- Stops at 15
        local Walls = 'Place'..tostring(num) -- It got pretty whiny with this
        local Char = 'Char'..tostring(num2)

        PhysicsService:CreateCollisionGroup(Walls) -- Sometimes
        PhysicsService:CreateCollisionGroup(Char) -- Sometimes

        local wall = v; local char = v2
        PhysicsService:SetPartCollisionGroup(wall, Walls) -- Sometimes here
        PhysicsService:SetPartCollisionGroup(char, Char) -- Errors here

        PhysicsService:CollisionGroupSetCollidable(Walls, Char, false)
        num2 = num2 + 1; num = num + 1
    end
end

Is there a simpler way than this? I feel I'm over-complicating it by a bit much. :P Many thanks appreciated. :)

0
10/10 question TheeDeathCaster 2368 — 6y
0
Why do you need a collision group for each individual part? NubgIe 15 — 6y
0
^ I tried doing it for models, but it kept erroring about how it had to be parts or something like that. TheeDeathCaster 2368 — 6y
0
Found the issue: Turns out I only needed the 2 groups, but to set the collisions after adding the parts to their groups. :P TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Try this

local PhysicsService = game:GetService('PhysicsService')
local pl = Workspace:WaitForChild('PLACE')
local fig = Workspace:WaitForChild('TEST_FIGURE')
PhysicsService:CreateCollisionGroup(“Walls”)
PhysicsService:CreateCollisionGroup(“Char”) 

function Parts(obj)
    local parts = {}
    for i, v in next, obj:GetChildren() do
        if v:IsA('BasePart') then
            table.insert(parts, v)
        end
    end
    return parts
end

local num = 0; local num2 = 0
for i, v in next, pl:GetChildren() do
    print(num, 'PLACE') -- Stops at 12
    for i2, v2 in next, Parts(fig) do
        PhysicsService:SetPartCollisionGroup(v, “Walls”)
        PhysicsService:SetPartCollisionGroup(v2, “Char”)
        PhysicsService:CollisionGroupSetCollidable(Walls, Char, false)
        num2 = num2 + 1; num = num + 1
    end
end
0
Could you please walk me through what you changed/what I did wrong? + The code didn't work. ;-; Something about invalid argument at line 23. TheeDeathCaster 2368 — 6y
0
Where it says Char on line 23 set Char to “Char” you need to put the quotations around it that was my bad I was on my phone SilentGalaxZy 53 — 6y
Ad

Answer this question