I am trying to set collision off in my game for both player and npcs. Player works just fine, but NPCs dont work. You can see in my script I had tried debugging using some prints statements. Here is the script.
Script
--// Services
local SSS = game:GetService('ServerScriptService')
local PhysicsService = game:GetService('PhysicsService')
local Players = game:GetService('Players')
--// Variables [Player Collision]
local PlayerGroup = PhysicsService:CreateCollisionGroup('PlayerCollide')
PhysicsService:CollisionGroupSetCollidable('PlayerCollide', 'PlayerCollide', false)
--// Variables [NPC Collisions]
local NPCGroup = PhysicsService:CreateCollisionGroup('NPCCollide')
PhysicsService:CollisionGroupSetCollidable('NPCCollide', 'NPCCollide', false)
PhysicsService:CollisionGroupSetCollidable('NPCCollide', 'PlayerCollide', false)
function NoCollidePlayer(model)
for _, parts in pairs(model:GetChildren()) do
if parts:IsA('BasePart') then
print("[Server] - Physics Service Loaded! Collision Group.. Player!")
PhysicsService:SetPartCollisionGroup(parts, 'PlayerCollide')
end
end
end
function playerAdded(player)
player.CharacterAdded:Connect(function(char)
char:WaitForChild('HumanoidRootPart')
char:WaitForChild('Head')
char:WaitForChild('Humanoid')
wait(0.1)
if char then
NoCollidePlayer(char)
end
end)
end
Players.PlayerAdded:Connect(playerAdded)
for _, parts in pairs(workspace.NPCs:GetDescendants()) do
if parts and parts:FindFirstChildWhichIsA('Humanoid') then
print('Part!')
if parts:IsA('BasePart') or parts:IsA('MeshPart') then
print("[Server] - Physics Service Loaded! Collision Group.. NPC!")
PhysicsService:SetPartCollisionGroup(parts, 'NPCCollide')
end
wait()
end
end
wait(.1)