I’ve been trying to make my NPCs to stop colliding with the player’s characters in-game.
I’ve tried using physics service, but that didn’t work. Here is the code for the physics service script, please help, and thanks!
local PS = game:GetService("PhysicsService")
PS:CreateCollisionGroup("Player")
PS:CollisionGroupSetCollidable("Player","Player",false)
PS:CreateCollisionGroup("NPC")
PS:CollisionGroupSetCollidable("NPC","NPC",false)
PS:CollisionGroupSetCollidable("NPC","Player",false)
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character:WaitForChild("HumanoidRootPart")
Character:WaitForChild("Head")
Character:WaitForChild("Humanoid")
for i,v in pairs(Character:GetChildren()) do
if v:IsA("BasePart") then
PS:SetPartCollisionGroup(v,"Player")
end
end
end)
end)
spawn(function()
for i = 1,math.huge do
for _, v in pairs(game.Workspace.NPCS:GetChildren()) do
if v and v:FindFirstChildOfClass("Humanoid") then
for _,b in pairs(v:GetChildren()) do
if b:IsA("Part") then
PS:SetPartCollisionGroup(b,"NPC")
end
wait()
end
end
wait()
end
wait(0.001)
end
end)
you have to use a runservice.Stepped loop on the client in order to make it non collidable; otherwise, it will just set the property right back to true
local npcs = game.Workspace.NPCS
game:GetService("RunService").Stepped:Connect(function()
for i,obj in pairs(npcs:GetDescendants()) do
if obj:IsA("BasePart") then
obj.HumanoidRootPart.CanCollide = false
end
end
end)
local npcs = game.Workspace.NPCS
for i,obj in pairs(npcs:GetDescendants()) do
if obj:IsA("BasePart") then
game:GetService("RunService").Stepped:Connect(function()
obj.CanCollide = false
end)
end
end