I was wondering if theirs a way to check if the npc is touching a door and then open the door but not let the player be able to do it that way since they use a prompt, and is there a way for the pathfinding to even ignore doors and find a pathway that goes through the door? thats alot to say but I would thank someone for helping me learn this!
door.Door.Touched:Connect(function(other)
-- check if npc touches door then opens it
if debounce == true then
debounce = false
tweenOpen:Play()
creakSFX:Play()
prompt.ActionText = "Close"
debounce = true
end
end)
local door = script.Parent
local isOpen = false
function openDoor()
if not isOpen then
isOpen = true
door.CFrame = door.CFrame * CFrame.new(0, 5, 0) -- Adjust the second value to how far up you want the door to move
end
end
function closeDoor()
if isOpen then
isOpen = false
door.CFrame = door.CFrame * CFrame.new(0, -5, 0) -- Adjust the second value to how far down you want the door to move
end
end
door.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
openDoor()
wait(3) -- Change this value to how long you want the door to stay open (in seconds)
closeDoor()
end
end)
this isnt what I wanted, I already made the script i need to figure out how I can check if an npc touches a door and if it does then it can open it. ONLY THE NPC not the player
local door = script.Parent -- Assumes the door is a direct child of the NPC model
local pathfindingService = game:GetService("PathfindingService")
local npc = script.Parent -- Assumes the script is a child of the NPC model
-- Define the destination for the NPC (in this case, the door)
local destination = door.Position
-- Calculate the path to the destination
local path = pathfindingService:CreatePath({
AgentRadius = 2, -- Adjust this value based on the size of your NPC
AgentHeight = 5, -- Adjust this value based on the height of your NPC
AgentCanJump = true,
AgentJumpHeight = 10, -- Adjust this value based on the jump capability of your NPC
AgentMaxSlope = 45,
})
path:ComputeAsync(npc.Position, destination)
-- Move the NPC along the path
path:MoveTo(destination)
-- Open the door (assuming the door has a script that opens it when touched)
door.Touched:Connect(function(hit)
if hit.Parent == npc then
-- Assume the door has a function called "Open" that opens the door
door:Open()
end
end)
check if the hit part has a humanoid inside of its parent and if its not a real player by checking if it doesnt exist in the Players container
door.Door.Touched:Connect(function(other)
if (other.Parent:FindFirstChild("Humanoid")) and (game:GetService("Players"):FindFirstChild(other.Parent.Name) == nil)
if debounce == true then
debounce = false
tweenOpen:Play()
creakSFX:Play()
prompt.ActionText = "Close"
debounce = true
end
end
end)