Hi
I am trying to make it so that the player won’t collide with selected objects. It doesn’t have to be at run time in fact it would be easier if it wasn’t. I tried using CollisionGroupId property and set it to 4 but it doesn’t change anything.
Use collision grop menu in model tab to add a collision group and follow instructions above
Quick code example here. Given two groups, here’s what you could do.
local ps = game:GetService("PhysicsService")
ps:CreateCollisionGroup("PlayersGroup")
ps:CreateCollisionGroup("NpcsGroup")
ps:CollisionGroupSetCollidable("PlayersGroup", "NpcsGroup", false)
for _, npc in pairs(npcs:GetChildren()) do
for _, v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"NpcsGroup")
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
task.wait()
for _, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"PlayersGroup")
end
end
end)
end)
More efficent ways to do that but the main purpose of that code is to just showcase what a collision group is and how you set them and create them.
Thanks for replying, I am using this service but the problem is I don’t know how to do it properly. So I made a collision group called “Grabbable” and made it so that players can’t collide with it but how would I assign an object to that group without using scripts because that would’ve been messy.
Its not that messy
local ps = game:GetService("PhysicsService")
local cannotCollideStuff = pathtostuff
ps:CreateCollisionGroup("PlayersGroup")
ps:CreateCollisionGroup("NpcsGroup")
ps:CollisionGroupSetCollidable("PlayersGroup", "NpcsGroup", false)
for _, npc in pairs(cannotCollideStuff:GetChildren()) do
for _, v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"NpcsGroup")
end
end
end
Parts of code
Ps if it broke its prob a typo
Thanks for replying, the thing is those parts would be in different folders so I would have to lop through literally every objects in the game or put a script in every one of those objects to set that for me. Either way I scrapped the idea, but thanks for helping.
local ps = game:GetService("PhysicsService")
local cannotCollideStuff = {path to folders1,path to folders2}
ps:CreateCollisionGroup("PlayersGroup")
ps:CreateCollisionGroup("NpcsGroup")
ps:CollisionGroupSetCollidable("PlayersGroup", "NpcsGroup", false)
for _, npc in pairs(cannotCollideStuff) do
for _, v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"NpcsGroup")
end
end
end
Part of this is psudo code but you should understand the concept of tables