code:
line that errors: path:ComputeAsync(torso.Position, plrhumanoid.Position)
i think it may be because the variable doesn’t have time to assign.
local pfs = game:GetService("PathfindingService")
local pathparams = {
["AgentHeight"] = 6.5,
["AgentRadius"] = 5,
["AgentCanJump"] = false,
["WaypointSpacing"] = math.huge
}
local waypoints = {}
local waypointindex = 1
script.Parent.PrimaryPart:SetNetworkOwner(nil)
local torso = script.Parent:WaitForChild("Torso")
local humanoid = script.Parent:WaitForChild("Humanoid")
local root = script.Parent:WaitForChild("HumanoidRootPart")
local anim = script.Parent.JumpscareAnimation
local animation = humanoid:LoadAnimation(anim)
local plrhumanoid
game.Players.PlayerAdded:Connect(function(plr)
plrhumanoid = plr.Character:WaitForChild("HumanoidRootPart")
end)
root.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
script.Parent:WaitForChild("Jumpscare"):Play()
animation:Play()
root.CanTouch = false
root.Anchored = true
plr.Character:WaitForChild("Humanoid").WalkSpeed = 0
plr.PlayerGui:WaitForChild("RunningScript"):Destroy()
end
end)
local path
local function Walk()
script.Parent.PrimaryPart:SetNetworkOwner(nil)
path = pfs:CreatePath(pathparams)
path:ComputeAsync(torso.Position, plrhumanoid.Position)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
waypointindex = 2
humanoid:MoveTo(waypoints[waypointindex].Position)
end
path.Blocked:Connect(function(blockedwaypointindex)
if blockedwaypointindex > waypointindex then
Walk()
end
end)
end
while task.wait() do
Walk()
end