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

Why are collision groups bugging for me?

Asked by 4 years ago
Edited 4 years ago

I've added two collision groups, one for the mobs, and one for the players, and set them to be unable to collide. This works like 80% of the time, but this happens sometimes: https://gyazo.com/e883406a2fb7631225257f34e485e1c7

I've tried manually making the collision groups and setting all of the properties, parts, etc beforehand, and I've also tried setting them in a script. Right now, I have it in a script, and I was wondering what was causing this.

Server Script in ServerScriptService:

local PS = game:GetService("PhysicsService")
PS:CreateCollisionGroup("players")
PS:CreateCollisionGroup("mobs")
PS:CollisionGroupSetCollidable("players","mobs",false) PS:CollisionGroupSetCollidable("mobs","mobs", false)

function NoCollide(model, group)
    for i,v in pairs(model:GetChildren()) do
        if v:IsA"BasePart" or v:IsA"UnionOperation" then 
            PS:SetPartCollisionGroup(v, group)
        end
    end
end

game.Workspace.Mobs.Sloobers.ChildAdded:Connect(function(Sloober) --Sloobers and Mobs are both folders
    NoCollide(Sloober, "mobs")
end)

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(c)
        NoCollide(c, "players")
        c.ChildAdded:Connect(function(child)
            NoCollide(child,"players")
        end)
    end)
end)

while wait(3) do --Spawning
    if #workspace.Mobs.Sloobers:GetChildren() < 15 then
        local Sloober = game.ServerStorage.Mobs.Sloober:Clone()
        Sloober:WaitForChild("HumanoidRootPart").Position = Vector3.new(math.random(0,30), 0.25, math.random(0, 30))
        Sloober.Parent = workspace.Mobs.Sloobers
        wait(3)
    end
end

To confirm that the groups are correct, I clicked on the mobs and player in the collision group window found in "Model", and the parts corresponded perfectly, meaning that they should work...

https://gyazo.com/03ad22382eeafbc6804b0c279c628aa8

https://gyazo.com/3dc9628b57eaeaab98e1a06f103c7e0a

1 answer

Log in to vote
0
Answered by 4 years ago

Never mind. The issue was in my model's eyes, fingers, and toes. They're children of head, legs, and arms, so i have to do GetDescendants instead of GetChildren for the NoCollide function

Ad

Answer this question