Hi! So I wanted to make a part, that lets for example NPCs through but not the player. How can I do that?
Thanks for reading!
Hi! So I wanted to make a part, that lets for example NPCs through but not the player. How can I do that?
Thanks for reading!
Have you tried to do this with collision groups?
How can I do that, or where, beacuse I couldn’t find it anywhere.
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local Wall = --path to the wall
PhysicsService:RegisterCollisionGroup("Characters")
PhysicsService:RegisterCollisionGroup("Walls")
PhysicsService:CollisionGroupSetCollidable("Characters", "Walls", false)
Wall.CollisionGroup = "Walls"
local function onDescendantAdded(descendant)
-- Set collision group for any part descendant
if descendant:IsA("BasePart") then
descendant.CollisionGroup = "Characters"
end
end
local function onCharacterAdded(character)
-- Process existing and new descendants for physics setup
for _, descendant in pairs(character:GetDescendants()) do
onDescendantAdded(descendant)
end
character.DescendantAdded:Connect(onDescendantAdded)
end
Players.PlayerAdded:Connect(function(player)
-- Detect when the player's character is added
player.CharacterAdded:Connect(onCharacterAdded)
end)
This is the only way so far, but there should be a better way like with NoCollisionConstraints
. Paging The opposite of NoCollisionConstraint: CollisionConstraint
Thanks, but this script lets me go through the wall, and not the NPCs, how can I fix that?
One way to do this is by creating a script that checks the player’s identity and applies a different set of rules to NPCs than to the player. You could also use a Scripted Part or a SurfaceGUI to block the player’s character from entering the area but allow NPCs to pass through. You could also use the Players/GetPlayerFromCharacter() function to check if a character is a player or NPC and apply different rules accordingly.