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.
Where did you even fire the coroutine, type coroutine.resume() function to fire a function the coroutine dosenât work by itself you need to fire it and then pause the coroutine when needed
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.
Just checked, and CanCollide is set to false on the server, and true on the client. Also, âWafflesâ was printed right when the map loaded. Not sure why.
EDIT: Waffles is printed when the map loads because I had the genius idea to put a print right at the start of the script for some reason. Wonderful.
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
coroutine.wrap(function()
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
print "Waffles"
script.Parent.Humanoid.WalkSpeed = 0
wait(1)
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)
end
end
end)()
end
end
Since doors are turned on for the client, if the NPCs RootPart network ownership is set to the client / player, it will collide with the door. Try setting the network ownership to nil.
For some reason, I get an error that says that I canât call :SetNetworkOwner on an anchored part or a part welded to an anchored part, even though not a single part in the NPC is anchored.