Hello. I’m making a game where enemies can’t collide with players or it will break the game.
I’m currently doing this script.
local PhysicsService = game:GetService("PhysicsService")
local PlayersGroup = PhysicsService:CreateCollisionGroup('Players')
local EnimiesGroup = PhysicsService:CreateCollisionGroup('Enimies')
PhysicsService:CollisionGroupSetCollidable('Players','Enimies',false)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for _,v in pairs(character:GetChildren()) do
if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
PhysicsService:SetPartCollisionGroup(v,'Players')
end
end
end)
end)
workspace.Enemies.ChildAdded:Connect(function(object)
for _,v in pairs(object:GetChildren()) do
if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
PhysicsService:SetPartCollisionGroup(v,'Enimies')
end
end
end)
But it seems to works only for the last player added and last, enemie added.
Please tell me how could I fix this.