You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Help for my pathfinding script
What is the issue? Include screenshots / videos if possible!
Stuttering/slow pathfinding
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i have for an embarrasing amount of time
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
i forgot to show the script its REALLY messy and insuficent but here it is :
local pathfinding = game:GetService(“PathfindingService”)
local char = script.Parent
local hum = char:WaitForChild(“Humanoid”)
local hrp = char:WaitForChild(“HumanoidRootPart”)
local function movetopath(location)
if Path1.Status == Enum.PathStatus.Success then
hum:MoveTo(location)
end
end
local function randommove(location)
if Path2.Status == Enum.PathStatus.Success then
hum:MoveTo(location)
end
end
while true do
game:GetService("RunService").Stepped:Wait()
print("A")
for i,Child in pairs(game.Workspace:GetChildren()) do -- Checks for Players in workspace
if Child.Name:sub(0,3) ~= "SCP" and Child.Name:sub(0,3) ~= "Inf" and Child.Name:sub(0,3) ~= "Rig" and Child:FindFirstChild("HumanoidRootPart") then
local plr = game.Players:GetPlayerFromCharacter(Child)
if (Child.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude <= 150 then
Path1:ComputeAsync(script.Parent.HumanoidRootPart.Position,Child.HumanoidRootPart.Position)
if Path1.Status == Enum.PathStatus.Success then
local waypoints = Path1:GetWaypoints()
script.Parent.Humanoid.Moving.Value = true
if script.Parent.Humanoid.Sitting.Value == true then
wait(6)
end
for i,v in pairs(waypoints) do
script.Parent.Humanoid:MoveTo(v.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
end
else
script.Parent.Humanoid.Moving.Value = false
script.Parent.Humanoid.Sitting.Value = true
end
end
end
I have fixed my problem by myself I appreciate everyone who helped me and if anyone want’s a pathfinding script : insert a script inside the rig and paste this inside of it! :
local pathfinding = game:GetService(“PathfindingService”)
local char = script.Parent
local hum = char:WaitForChild(“Humanoid”)
local hrp = char:WaitForChild(“HumanoidRootPart”)
for i,BasePart in pairs(script.Parent:GetChildren()) do
if BasePart:IsA("BasePart") or BasePart:IsA("MeshPart") then
BasePart:SetNetworkOwner(nil)
end
end
local function Stuck(v)
script.Parent.Humanoid:MoveTo(v.Position)
end
while true do
wait(0.1)
for i,Child in pairs(game.Workspace:GetChildren()) do -- Checks for Players in workspace
if Child:FindFirstChild("HumanoidRootPart") then
local plr = game.Players:GetPlayerFromCharacter(Child)
if (Child.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude <= 50 then -- Change 50 to whatever distance you want your NPC to lock onto you from higher means further away less means less further
Path1:ComputeAsync(script.Parent.HumanoidRootPart.Position,Child.HumanoidRootPart.Position)
if Path1.Status == Enum.PathStatus.Success then
local waypoints = Path1:GetWaypoints()
if tonumber(script.Parent.WalkSpeed.Value) == 2 or tonumber(script.Parent.WalkSpeed.Value) > 2 then
script.Parent.Humanoid:MoveTo(plr.Character.HumanoidRootPart.Position)
print('No Waypoitns')
else
for i,v in pairs(waypoints) do
Stuck(v)
script.Parent.Humanoid.MoveToFinished:Wait()
end
if tonumber(script.Parent.WalkSpeed.Value) == 2 or tonumber(script.Parent.WalkSpeed.Value) > 2 then
script.Parent.Humanoid:MoveTo(plr.Character.HumanoidRootPart.Position)
print('No waypoints')
end
end
end
end
end
end