Guest User

Untitled

a guest
Nov 23rd, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. -- Attack / chase behaviour
  2. local function attack(player)
  3.     if not player or targetedPlayer then return end
  4.     if not player.Character or not player.Character.PrimaryPart then return end
  5.  
  6.     targetedPlayer = player
  7.     -- Plays a scary sound from a Folder SCP173 called "Vuewing", that is the sound that plays the second you look at 096s face
  8.     scarePlayer:FireClient(targetedPlayer, "scp173", "Viewing", NPC.Head)
  9.     triggerAnim:Play()
  10.     if hrp:FindFirstChild("Look") then hrp.Look:Play() end
  11.     task.wait(0.2)
  12.     if hrp:FindFirstChild("Trigger") then hrp.Trigger:Play() end
  13.  
  14.     task.wait(triggerTime)
  15.  
  16.     -- prepare path and follow
  17.     local currentWaypoints = {}
  18.     local currentIndex = 1
  19.     local lastPlayerPos = player.Character.PrimaryPart.Position
  20.  
  21.     local function refreshPath()
  22.         local success, err = tryComputePath(NPC.PrimaryPart.Position, player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position)
  23.         if not success then
  24.             table.clear(currentWaypoints)
  25.             return
  26.         end
  27.         currentWaypoints = path:GetWaypoints()
  28.         currentIndex = 1
  29.     end
  30.  
  31.     refreshPath()
  32.  
  33.     -- start chase animations/sounds
  34.     runAnim:Play()
  35.     if hrp:FindFirstChild("Scream") then hrp.Scream:Play() end
  36.     if scp096Remote then scp096Remote:FireClient(player) end
  37.  
  38.     -- monitor player movement and refresh path if necessary
  39.     local refreshTask = task.spawn(function()
  40.         while targetedPlayer do
  41.             if not player.Character or not player.Character.PrimaryPart then
  42.                 break
  43.             end
  44.             local curPos = player.Character.PrimaryPart.Position
  45.             if (curPos - lastPlayerPos).Magnitude >= 2 then
  46.                 lastPlayerPos = curPos
  47.                 refreshPath()
  48.             end
  49.             task.wait(0.25)
  50.         end
  51.     end)
  52.  
  53.     -- follow current waypoints
  54.     while targetedPlayer and currentIndex <= #currentWaypoints do
  55.         if not player.Character or not player.Character.PrimaryPart or player.Character.Humanoid.Health <= 0 then
  56.             break
  57.         end
  58.  
  59.         humanoid.WalkSpeed = 35
  60.         local wp = currentWaypoints[currentIndex]
  61.         if wp and wp.Position then
  62.             humanoid:MoveTo(wp.Position)
  63.             humanoid.MoveToFinished:Wait()
  64.         end
  65.         currentIndex = currentIndex + 1
  66.     end
  67.  
  68.     -- Kill player once the NPC has reached final waypoint
  69.     -- We do not need any check if the NPC is on its final waypoint since the while loop will only end if all waypoint were used
  70.    
  71.     if targetedPlayer and player.Character and player.Character.PrimaryPart and player.Character.Humanoid.Health > 0 then
  72.         if hrp:FindFirstChild("Kill") then hrp.Kill:Play() end
  73.  
  74.         local particle = script:FindFirstChild("Particle")
  75.         if particle and player.Character.PrimaryPart:FindFirstChild("RootAttachment") then
  76.             local pClone = particle:Clone()
  77.             pClone.Parent = player.Character.PrimaryPart.RootAttachment
  78.             pClone:Emit(5)
  79.             Debris:AddItem(pClone, 2)
  80.         end
  81.  
  82.         if player.Character:FindFirstChild("Humanoid") then
  83.             player.Character.Humanoid:TakeDamage(math.huge)
  84.         end
  85.     end
  86.  
  87.     targetedPlayer = nil
  88.     runAnim:Stop()
  89.     if hrp:FindFirstChild("Scream") then hrp.Scream:Stop() end
  90.     humanoid.WalkSpeed = 8
  91. end
Advertisement
Add Comment
Please, Sign In to add comment