#Pathfinding

1 messages · Page 1 of 1 (latest)

gentle remnant
#
local PathfindingService = game:GetService("PathfindingService")

local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local rootpart = npc.HumanoidRootPart

while true do
    local target = nil

    if target and target:FindFirstChild("HumanoidRootPart") then
        local targetRoot = target.HumanoidRootPart
        local path = PathfindingService:CreatePath()

        path:ComputeAsync(rootpart.Position, targetRoot.Position)
        local waypoints = path:GetWaypoints()

        if path.Status == Enum.PathStatus.Success then
            for i, waypoint in pairs(waypoints) do
                humanoid:MoveTo(waypoint.Position)
                humanoid.MoveToFinished:Wait()

                if i >= 2 then
                    break
                end
            end
        end
    end
    task.wait(0.1)
end
``` how do i make it run to me? its my first day of scripting
hazy shard
#

I'm pretty sure u have to delete the part: while true do target == nil

#

Cuz then target is always nil cuz that an infinite loop

fierce bison
#

why are you pathfinding

#

on the very

#

first day

#

of scripting

gentle remnant
#

these are all the scripts ive done so far if ur interested

#

local door = game.Workspace.Door
local button = game.Workspace.Button1
local clickDetector = button.ClickDetector
for index, value in pairs(door:GetDescendants()) do
if value:IsA("BasePart") then
value:SetAttribute("OriginalTransparency", value.Transparency)
end
end
clickDetector.MouseClick:Connect(function()
for index, value in pairs(door:GetDescendants()) do
if value:IsA("BasePart") then
value.Transparency = 0.7
value.CanCollide = false
end
end
print("Door opened")
task.wait(0.5)
for index, value in pairs(door:GetDescendants()) do
if value:IsA("BasePart") then
local original = value:GetAttribute("OriginalTransparency")
value.Transparency = original
value.CanCollide = true
end
end
print("Door closed")
end)

local lightsfolder = game.Workspace.SecurityLights
local button = game.Workspace.ToggleLockdown
local sound = button.Alert
local clickdetector = button.ClickDetector
local isLockedDown = false
clickdetector.MouseClick:Connect(function()
if isLockedDown == false then
sound:Play()
for index, value in pairs(lightsfolder:GetDescendants()) do
if value:IsA("BasePart") then
value.Material = Enum.Material.SmoothPlastic
value.Color = Color3.fromRGB(255, 0, 0)
end
end
isLockedDown = true
print("Lockdown Activated.")
else
sound:Stop()
for index, value in pairs(lightsfolder:GetDescendants()) do
if value:IsA("BasePart") then
value.Material = Enum.Material.Neon
value.Color = Color3.fromRGB(255, 255, 255)
end
end
isLockedDown = false
print("Lockdown Off.")
end
end)
#
local tweenpart = game.Workspace.TweenPart
local tweenbutton = game.Workspace.TweenButton
local clickdetector = tweenbutton.ClickDetector
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
1,
Enum.EasingStyle.Exponential,
Enum.EasingDirection.Out
)
local originalposition = tweenpart.Position
local isOpen = false
clickdetector.MouseClick:Connect(function()
if isOpen == false then
local goal = {
Position = originalposition + Vector3.new(0, 0, 10)
}
local tween = TweenService:Create(tweenpart, tweenInfo, goal)
tween:Play()
isOpen = true
else
local goal = { Position = originalposition }
local tween = TweenService:Create(tweenpart, tweenInfo, goal)
tween:Play()
isOpen = false
end
end)
local lava = game.Workspace.Lava
local isTouching = false
lava.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and isTouching == false then
isTouching = true
workspace:GetPartsInPart(lava)
while isTouching == true do
local foundsomeone = false
for _, part in pairs(workspace:GetPartsInPart(lava)) do
local character = part.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
foundsomeone = true
humanoid.Health = humanoid.Health - 20
end
end
if foundsomeone == false then
isTouching = false
end
wait(0.75)
end
end
end)
#
local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local rootPart = npc:WaitForChild("HumanoidRootPart")
while true do
local target = Players:GetPlayers()[1]
print("Target:", target)
if target and target.Character then
print("Character found")
local targetRoot = target.Character:FindFirstChild("HumanoidRootPart")
print("TargetRoot:", targetRoot)
if targetRoot then
local path = PathfindingService:CreatePath()
path:ComputeAsync(rootPart.Position, targetRoot.Position)
print("Path status:", path.Status)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
print("Waypoints:", #waypoints)
for _, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end
end
end
task.wait(0.1)
end
charred monolith
#

hungry ass ate them all

gentle remnant
cinder frostBOT
#

studio** You are now Level 2! **studio

charred monolith
gentle remnant
#

yo i do not know what you're talking about

charred monolith
#

💔

fierce bison
#

roblox does the indentation automatically for you???

#

and if you came from python you would also natrually indent as well

#

since python doesnt have ends it just relies on indentation

gentle remnant
#

its indented i just pasted it in like that

#

@fierce bison