Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I resolve path finding not working properly?

Asked by 3 years ago

This is my code

--//Services local pfs = game:GetService("PathfindingService") local RS = game.ReplicatedStorage local Floors = game.Workspace.MapGrid:GetChildren()

--//Setup local f = Instance.new("Folder", workspace) f.Name = "CurrentGeneratedRooms"

for _,v in pairs(workspace.MapGrid:GetChildren()) do v.Transparency = 1 end for _,v in pairs(game.ReplicatedStorage.Rooms:GetChildren()) do v.PrimaryPart = v.Floor end

local rooms = game.ReplicatedStorage.Rooms:GetChildren() local rotations = {0,90,180,270} -- directions the rooms can be rotated in local roomGenerated = false

--//Functions local function generateRooms() f:ClearAllChildren()

for _,floor in pairs(workspace.MapGrid:GetChildren()) do
    local chosenRoom = rooms[math.random(1, #rooms)]:Clone() --Pick random Room
    chosenRoom:SetPrimaryPartCFrame(floor.CFrame * CFrame.Angles(0, math.rad(rotations[math.random(1,#rotations)]), 0))
    chosenRoom.Parent = f
end

end local function GiveLoadingScreen(player) local gui = script.Loading:Clone() gui.Parent = player.PlayerGui end

--//Main --Give Loading Screen for _,player in pairs(game.Players:GetPlayers()) do GiveLoadingScreen(player) end game.Players.PlayerAdded:Connect(function(player) if roomGenerated == false then GiveLoadingScreen(player) end end)

--Generate Rooms local path = nil repeat generateRooms() --Generate rooms randomly

--Check if there is a path from start to end
path = pfs:CreatePath()
path:ComputeAsync(workspace.Start.Floor.Position, workspace.End.Floor.Position)

until path.Status == Enum.PathStatus.Success

roomGenerated = true

for _,player in pairs(game.Players:GetPlayers()) do if player.PlayerGui:FindFirstChild("Loading") then player.PlayerGui.Loading:Destroy() end end

I download it off a free model https://www.roblox.com/library/7140368448/Dungeon-Generator And I understand how it works the issue i have is I believe with the last part where it checks if there is a path that leads from the start to end.

I have a Floor in a group called Start and another one in End yet when I play it there never is a path that leads to the end you always get stuck at one point and that is what I don`t understand what is wrong with this code.

I'm a beginner in coding so maybe it is a very dumb issue but all help would be aprecieated <3

Answer this question