#My rig will not move at all with this script.

1 messages · Page 1 of 1 (latest)

ember pecan
#

local monster = workspace:WaitForChild("Monster")
local humanoid = monster:WaitForChild("Humanoid")
local rootPart = monster:WaitForChild("HumanoidRootPart")

local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local FOLLOW_DISTANCE = 100 -- Range to detect players
local WANDER_RADIUS = 50 -- How far the monster can wander
local PATH_RECALC_TIME = 2

local currentPath = nil
local targetPlayer = nil
local lastPathTime = 0

-- Utility function to get a random position near the monster
local function getRandomWanderPosition()
local randomOffset = Vector3.new(
math.random(-WANDER_RADIUS, WANDER_RADIUS),
0,
math.random(-WANDER_RADIUS, WANDER_RADIUS)
)
local origin = rootPart.Position + randomOffset
local ray = Ray.new(origin + Vector3.new(0, 10, 0), Vector3.new(0, -20, 0))
local part, position = workspace:FindPartOnRay(ray, monster)
if part then
return position
else
return rootPart.Position
end
end

#

-- Finds the nearest player within range
local function findNearestPlayer()
local closestPlayer = nil
local closestDistance = FOLLOW_DISTANCE
for _, player in ipairs(Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
local dist = (player.Character.HumanoidRootPart.Position - rootPart.Position).Magnitude
if dist < closestDistance then
closestPlayer = player
closestDistance = dist
end
end
end
return closestPlayer
end

-- Move the monster using a path
local function moveToPosition(targetPosition)
local path = PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentCanClimb = true,
})

path:ComputeAsync(rootPart.Position, targetPosition)

if path.Status == Enum.PathStatus.Complete then
    currentPath = path
    for _, waypoint in pairs(path:GetWaypoints()) do
        humanoid:MoveTo(waypoint.Position)
        humanoid.MoveToFinished:Wait()
    end
end

end

-- Main loop
RunService.Heartbeat:Connect(function(deltaTime)
if tick() - lastPathTime > PATH_RECALC_TIME then
lastPathTime = tick()
targetPlayer = findNearestPlayer()

    if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("HumanoidRootPart") then
        local targetPos = targetPlayer.Character.HumanoidRootPart.Position
        moveToPosition(targetPos)
    else
        local wanderPos = getRandomWanderPosition()
        moveToPosition(wanderPos)
    end
end

end)

safe thicket
#

dont use humanoid.MoveToFinished:Wait()

#

2nd dont rely on ai

ember pecan
#

im new and dont know too much about scripting

safe thicket