So I am working on this npc system. Where the npc’s just walk to the nearest computer and sit on it. For some reason it keeps on warning out no seat found. Does anyone know the problem?? By the way the thing Multi does exist too.
local seat = nil
spawn(function()
while wait(4) do
while script.Parent.Humanoid.Sit == false do
local Closest = nil
local ClosestDis = math.huge
for i, v in pairs(script.Parent.Parent:GetDescendants()) do
if v:IsA("Seat") then
print(v.Name)
if not v.Occupant and v.Parent.Parent.Parent:FindFirstChild("Multi") then
print(v.Name)
local distance = (v.Position - script.Parent.Position).Magnitude
if distance < ClosestDis then
Closest = v
ClosestDis = distance
end
end
end
end
if Closest then
warn(Closest.Name)
script.Parent.Humanoid:MoveTo(Closest.Position)
wait(5)
if script.Parent.Humanoid.Sit == false then
script.Parent.HumanoidRootPart.CFrame = Closest.CFrame
end
else
warn("No seat found")
end
wait(1)
end
end
end)
spawn(function()
while true do
repeat wait(0.05) until script.Parent.Humanoid.Sit == true
script.Parent.Head["Audio/keyboard typing"]:Play()
anim = script.Parent.Humanoid:LoadAnimation(script.Parent.Humanoid.Animation)
anim:Play()
repeat wait(0.02) until script.Parent.Humanoid.Sit == false
anim:Stop()
end
end)