collision filtering is quite new to me, so sorry if i sound like rubbish.
with this script, i disable collisions between players when a player enters the game:
local physics = game:GetService("PhysicsService")
local pcollide = "Players"
local ocollide = "Player"
physics:CreateCollisionGroup(pcollide)
physics:CreateCollisionGroup(ocollide)
physics:CollisionGroupSetCollidable(pcollide, pcollide, false)
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
setCollisionGroupRecursive(char)
end)
end)
function setCollisionGroupRecursive(object)
if object:IsA("MeshPart") then
physics:SetPartCollisionGroup(object, pcollide)
end
if object:IsA("Part") then
physics:SetPartCollisionGroup(object, pcollide)
end
for _,child in pairs(object:GetChildren()) do
setCollisionGroupRecursive(child)
end
end
and with this script, i create another collision group to enable player collisions to whoever is in the created collision group when a text button is pressed:
local plr = script.Parent.Parent.Parent.Parent.Parent
local char = game:WaitForChild(plr.Name)
local physics = game:GetService("PhysicsService")
local pcollide = "Players"
local ocollide = "Player"
script.Parent.MouseButton1Click:connect(function()
physics:CollisionGroupSetCollidable(ocollide, ocollide, true)
setCollisionGroupRecursive(char)
function setCollisionGroupRecursive(object)
if object:IsA("MeshPart") then
physics:SetPartCollisionGroup(object, ocollide)
end
if object:IsA("Part") then
physics:SetPartCollisionGroup(object, ocollide)
end
for _,child in pairs(object:GetChildren()) do
setCollisionGroupRecursive(child)
end
end
end)
the problem is that the player collisions are still disabled, which probably means they havent been added to the collision group where it enables player collisions, since both scripts dont give off any errors. any help? thanks.
|