For some reason there is this huge problem in my code. Only the NPC’s go to one computer. Does anyone know why?
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.ClassName ~= "Seat" then continue end
v:GetPropertyChangedSignal("Occupant"):Connect(function()
local s, e = pcall(function()
local person = v.Occupant
if person.Parent == script.Parent then
seat = v
end
end)
end)
game.Workspace.DescendantRemoving:Connect(function(h)
if h == seat then
script.Parent.Humanoid.Sit = false
end
end)
if not Closest then Closest = v end
if (Closest.Position - v.Position).Magnitude < ClosestDis and Closest.Parent.Parent.Parent:FindFirstChild("Multi") and Closest.Occupant ~= "Humanoid" then
warn(Closest)
Closest = v
ClosestDis = (Closest.Position - v.Position).Magnitude
else
warn("no seat found")
print(Closest.Occupant)
print(Closest.Parent.Parent.Parent:FindFirstChild("Multi"))
end
end
if Closest.Occupant ~= "Humanoid" then
script.Parent.Humanoid:MoveTo(Closest.Position)
wait(5)
if script.Parent.Humanoid.Sit == false then
script.Parent.HumanoidRootPart.CFrame = Closest.CFrame
end
end
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)