#Can someone help me with this script? The monster wants to catch me through the walls.

8 messages · Page 1 of 1 (latest)

rain current
#

local PathfindingService = game:GetService("PathfindingService")

local mob = script.Parent
local Humanoid = mob.Humanoid
mob.PrimaryPart:SetNetworkOwner(nil)

local function canSeeTarget(target)

local origin = mob.HumanoidRootPart.Position
local direction = (target.HumanoidRootPart.Position - mob.HumanoidRootPart.Position).Unit * 40
local ray = Ray.new(origin, direction)

local hit, pos = workspace:FindPartOnRay(ray, mob)

if hit then
    if hit:IsDescendantOf(target) then
        
        return true
        
    end
else
    return false
end

end

local function findTarget()

local players = game.Players:GetPlayers()
local maxDistance = 40
local nearestTarget

for i, player in pairs(players) do

    if player.Character then

        local target = player.Character
        local distance = (mob.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude

        if distance < maxDistance and canSeeTarget(target) then
            nearestTarget  = target
            maxDistance = distance
            mob.HumanoidRootPart.ISEEYOU:Play()
        end
    end
end

return nearestTarget

end

local function getPath(destination)

local pathParams = {

    ["AgentHight"] = 12,
    ["AgentRadious"] = 10,
    ["AgentCanJump"] = false,

}

local path = PathfindingService:CreatePath(pathParams)

path:ComputeAsync(mob.HumanoidRootPart.Position, destination.Position)

return path

end

#

local function attack(target)

local distance = (mob.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude

if distance > 8 then

    Humanoid:MoveTo(target.HumanoidRootPart.Position)
else
    local player = game.Players:GetPlayerFromCharacter(target)
    
    game.ReplicatedStorage.RustyGrinJumpscare:FireClient(player)
    game.ReplicatedStorage.KillerNameRustyGrin:FireClient(player)
end

end
local function walkTo(destination)

local path = getPath(destination)

if path.Status == Enum.PathStatus.Success then

    for i, waypoint in pairs(path:GetWaypoints()) do

        local target = findTarget()

        if target and target.Humanoid.Health > 0 then
            attack(target)
            break
        else
            Humanoid:MoveTo(waypoint.Position)
            Humanoid.MoveToFinished:Wait()
        end
    end
else
    Humanoid:MoveTo(destination.Position - (mob.HumanoidRootPart.CFrame.LookVector * 10))
end

end

local function patrol()

local waypoints = workspace.World.WaypointsRustyGrin:GetChildren()
local randomNum = math.random(1, #waypoints)

walkTo(waypoints[randomNum])

end

while wait(0.2) do

patrol()

end

#

PLEASE HELP ME!

leaden arrow
#

Format properly.

rain current
#

And it looks like that because it’s on discord not on Roblox studio

fair swallow