Basically, there is an NPC that wanders around the area in my game. This NPC, when it comes into contact with a door, will open it. However, the NPC collides with these doors, even though the doors have collisions off and collisions are only turned on for the client. Anyone know what to do about this?
My gosh this is like the 6th problem I’ve had with doors making this game… I’ve had less problems combined making the rest of the game! (4)
I have removed it, but as stated in the note above it, it needs to be there so that the for loop can loop through all of the doors. My solution to this was to fire an event that activated another script containing the while loop, and in the end, it changed nothing.
coroutine.wrap() has always worked in such a way (for me at least) where it just automatically fires, and either way, that’s not the issue, as I stated previously that I tested it with firing a bindable event, and that didn’t work either.
Where’s the script that moves the NPC, and does it see the door as a blockage instead of being open?
You say the NPC ‘collides’ with a CanCollide off door, so I’d look into the NPC script rather than the door script.
The NPC does attempt to pathfind through the door, it doesn’t see the door as blockage. This is because, on the server, the door cannot be collided with. The way I prevent players from walking through the doors is by setting CanCollide to true on the client, meaning that it doesn’t effect the server. However, for some reason, the NPC still tries to pathfind through the door, but it collides with it for some reason.
local chosenMap = game:GetService("ReplicatedStorage").Values.Chosen.ChosenMap
local rayOrigin = script.Parent.HumanoidRootPart
--Get all of the descendants of the current map
for _, door in pairs(game.Workspace.LoadedMaps:FindFirstChild(chosenMap.Value):GetDescendants()) do
--Is it a door?
if door:FindFirstChild("IsOpen") then
--Coroutine so that the for loop can continue and not get stuck on the while loop
while wait() do
--Check if near door & door is unlocked and closed
if Ray.new(rayOrigin.Position, door.Position - rayOrigin.Position):Distance(door.Position) <= 5 and not door.IsOpen.Value and not door.IsOpening.Value and (not door:FindFirstChild("Unlocked") or door:FindFirstChild("Unlocked").Value) then
script.Parent.Humanoid.WalkSpeed = 0
script.Parent.Humanoid.WalkSpeed = 10
--Open the door
require(game.ServerScriptService.Scripts.Functions.DoorFunctionStorage).DoorOpenClose(game:GetService("RunService"), door.Parent, door.Parent:GetPivot(), not door:FindFirstChild("IsOpen").Value, door:FindFirstChild("IsOpen").Value, door.Orientation.Y, false)