Hello! Is it possible to make a part that can’t collide with players, but can collide with other parts?
That can be made possible with CollisionGroups! This Developer Hub article explains how CollisionGroups work alongside a couple of examples.
You can cross-reference that with this Developer Hub article that covers player-part collisions with Team-Only doors.
Is there a script I could put in the part?
If the part that contains the script falls into the void, it’d delete the script with it, so I would recommend placing the script elsewhere, such as the ServerScriptService
. This would also make it easier to reference multiple parts if you’re planning on having more than one that does not collide with a player’s Character.
I don’t have the time to provide an in-depth explanation of it atm and since there’s different ways of setting it up, I’m not sure what your preferences would be (whether you’d want to create the CollisionGroups during the editing process & then add different parts into the specific groups via scripts, or do everything via scripts).
I’d still advise you to read the articles that I linked for more information in the meantime, as it could enable you to have a better understanding of how it works before utilizing it in your game.
Example:
local part = -- Choose
game.PhysicsService:CreateCollisionGroup("Thing1")
game.PhysicsService:CreateCollisionGroup("Thing2")
game.PhysicsService:CollisionGroupSetCollidable("Thing1","Thing2",false)
game.PhysicsService:SetPartCollisionGroup(part,"Thing1")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local stuff = player.Character:GetChildren()
local i = 1
for i = 1, #stuff do
local characterPart = stuff[i]
if characterPart:isA("Part") or characterPart:isA("MeshPart") then
game.PhysicsService:SetPartCollisionGroup(characterPart,"Thing2")
end
end
end)
end)
I believe so, though I am unsure.
Is it possible to make a script that I could just put into the part?
You can set part variable to script.Parent. Or do you want me to make it a touched function?
I’m looking if there’s a script that I can put inside a part that makes it so it can’t collide with players.
Yes. You can just put that script inside a part and set the part variable to script.Parent
So it would be
game.PhysicsService:CreateCollisionGroup("Thing1")
game.PhysicsService:CreateCollisionGroup("Thing2")
game.PhysicsService:CollisionGroupSetCollidable("Thing1","Thing2",false)
game.PhysicsService:SetPartCollisionGroup(part,"Thing1")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local stuff = player.Character:GetChildren()
local i = 1
for i = 1, #stuff do
local characterPart = stuff[i]
if characterPart:isA("Part") or characterPart:isA("MeshPart") then
game.PhysicsService:SetPartCollisionGroup(characterPart,"Thing2")
end
end
end)
end)
I’m unfamiliar with this, so please correct me.
Can’t you just make it more organized and put the parts in a table, so you don’t have to put a script in every single part you want disabled for player?
A LocalScript should work only for players: CanCollide = false
.
Doesn’t LocalScript only affect LocalPlayer?
It should; try the script below
-- Put in StarterGui as a LocalScript
local part = {game.Workspace.Part1, game.Workspace.Part2} -- You can change and add
game:GetService("RunService").Stepped:connect(function()
for i,v in pairs(part) do
if v:isA("Part") then
v.CanCollide = false
end
end
end
It only needs to be one part. Also, does that script make it so the part doesn’t collide with all players?
Yes. It will apply to all players (“cliently”)
It seems to not work. Is it possible you can edit the first script you gave me so it’s ready for me to put into a part? Sorry if this sounds demanding, I’m not trying to be.
Did you configure the table???
Did you make the script a local script in startergui?
I made the script a localscript in startergui, I don’t really know how tables and stuff work. That’s why I asked for a script that I can just put into a part.
I edited the script if that’s what you’re asking.
Where is the part located?
Example:
game.Workspace.Part
game.ServerStorage.Logs.wood is what I put. It’s inside serverstorage, inside a model called “Logs” and the part is called “wood”
Try both
-- Put in StarterGui as a LocalScript
local part = {game.ServerStorage.Logs.wood} -- If you clone this then look at the other script below
game:GetService("RunService").Stepped:connect(function()
for i,v in pairs(part) do
if v:isA("Part") then
v.CanCollide = false
end
end
end
-- Put in StarterGui as a LocalScript
local part = {game.Workspace:WaitForChild("Logs").wood}
game:GetService("RunService").Stepped:connect(function()
for i,v in pairs(part) do
if v:isA("Part") then
v.CanCollide = false
end
end
end