I am trying to make a rooms entity pathfinding script where the entity goes to the next part, and it isn’t working. When the next room is a corner room, the entity goes to the corner of the current room.
here is my code:
for i, v:Part in pairs(workspace:GetDescendants()) do
if v.Name == "RoomDoor" and v:IsA "Part" then
v.Transparency = 0
v.CanCollide = true
v.ProximityPrompt.Triggered:connect(function(sus)
print("Door opened")
v.Transparency = 0.5
v.CanCollide = false
function spawnEntity()
print("EntitySpawned")
local clone = workspace["A-20"]:Clone()
clone.Parent = workspace
clone:PivotTo(workspace["The Lobby"].EntitySpawn.CFrame)
for i, v in pairs(_G.rooms_exist) do
clone.Humanoid:MoveTo(v.Position)
clone.Humanoid.MoveToFinished:Wait()
end
end
local WillEntitySpawn = math.random(1, 5)
if WillEntitySpawn == 1 then
spawnEntity()
end
end
)
end
end