I have a path (not a straight line) that I want a character to follow, but my character is supposed to be slow, and my current pathfinding script will just skip the point it’s supposed to pathfind and move to the next point.
repeat
task.wait()
until (script.Parent):IsA("Model")
local col = require(game.ServerStorage:WaitForChild("Collisions"))
local inunderground
local UndergroundStatusVal
local hum = script.Parent:WaitForChild("Humanoid")
local hrp = script.Parent:WaitForChild("HumanoidRootPart")
if script.Parent.Name == "Umbra Monstrum" then
inunderground = script.Parent:WaitForChild("IsUnderground")
UndergroundStatusVal = hum.Parent:WaitForChild("UndergroundStatusVal")
end
local PointIndex
local CurrentPathPoint = hum.Parent:WaitForChild("CurrentPathPoint")
local hrpy = hrp.CFrame.Y
print(hrpy)
local path = script.Parent:WaitForChild("ChosenPath")
local pathway = game.Workspace:WaitForChild("PathWay")
local chosenPath = pathway:WaitForChild(path.Value)
local merged = pathway:WaitForChild("Merge")
local chosenchildren = chosenPath:GetChildren()
local mergedchildren = merged:GetChildren()
local pathpoints = {}
local undergroundpath = (game.Workspace:WaitForChild("UndergroundPathWay")):GetChildren()
col.SetPartToGroup(undergroundpath, "Paths and Doorways")
for i, v in pairs(chosenchildren) do
table.insert(pathpoints, v)
end
for i, v in pairs(mergedchildren) do
table.insert(pathpoints, v)
end
print(pathpoints)
PointIndex = 1
print(pathpoints[PointIndex])
local MoveToPos
local MoveToInst
if script.Parent.Name == "Umbra Monstrum" then
UndergroundStatusVal.Changed:Connect(function(a)
print("Gottem")
print(a)
if a == 1 then
print("I DID IT")
print(PointIndex)
print(pathpoints[PointIndex])
MoveToInst = pathpoints[PointIndex]
print(MoveToInst)
MoveToPos = MoveToInst.Position
print(MoveToPos)
hum:MoveTo(MoveToPos, MoveToInst)
end
end)
inunderground:GetPropertyChangedSignal("Value"):Connect(function()
if inunderground.Value == true then
print(PointIndex)
print(pathpoints[PointIndex])
MoveToInst = pathpoints[PointIndex]
print(MoveToInst)
MoveToPos = MoveToInst.Position
print(MoveToPos)
hum.WalkSpeed = 25
hum:MoveTo(MoveToPos - Vector3.new(0, -8, 0))
task.wait(math.random(1, 2))
hum.WalkSpeed = 0
inunderground.Value = false
end
end)
end
hum.MoveToFinished:Connect(function()
print(hrp.CFrame.Y)
if script.Parent.Name == "Umbra Monstrum" then
if UndergroundStatusVal.Value == 1 or inunderground.Value == true then --Goals for tomorrow (In case I forget) make monster move when it goes back up, use GetPropertyChangedSignal for UndergroundStatusVal
PointIndex += 1
print(pathpoints[PointIndex])
MoveToInst = pathpoints[PointIndex]
MoveToPos = MoveToInst.Position
print(MoveToPos)
if script.Parent.Name == "Umbra Monstrum" then
if inunderground.Value == true then
hum:MoveTo(MoveToPos - Vector3.new(0, -8, 0))
else
hum:MoveTo(MoveToPos, MoveToInst)
end
else
hum:MoveTo(MoveToPos, MoveToInst)
end
end
else
PointIndex += 1
print(pathpoints[PointIndex])
MoveToInst = pathpoints[PointIndex]
MoveToPos = MoveToInst.Position
print((hum.Parent.PrimaryPart.Position - pathpoints[PointIndex - 1].Position).Magnitude)
if (hum.Parent.PrimaryPart.Position - pathpoints[PointIndex - 1].Position).Magnitude < 0.1 then
hum:MoveTo(MoveToPos, MoveToInst)
else
repeat --This repeat loop is SUPPOSED to keep looping until the monster reaches its destination, but it doesn't.
hum:MoveTo(pathpoints[PointIndex - 1].Position, pathpoints[PointIndex - 1])
hum.MoveToFinished:Wait()
until (hum.Parent.PrimaryPart.Position - pathpoints[PointIndex - 1].Position).Magnitude < 0.1
end
end
end)
hum:MoveTo(pathpoints[PointIndex].Position, pathpoints[PointIndex])
(My script is so messy )
Simpler explanation:
Hopefully you get it : )
Thank you for taking your time to read this