Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Attack / chase behaviour
- local function attack(player)
- if not player or targetedPlayer then return end
- if not player.Character or not player.Character.PrimaryPart then return end
- targetedPlayer = player
- -- Plays a scary sound from a Folder SCP173 called "Vuewing", that is the sound that plays the second you look at 096s face
- scarePlayer:FireClient(targetedPlayer, "scp173", "Viewing", NPC.Head)
- triggerAnim:Play()
- if hrp:FindFirstChild("Look") then hrp.Look:Play() end
- task.wait(0.2)
- if hrp:FindFirstChild("Trigger") then hrp.Trigger:Play() end
- task.wait(triggerTime)
- -- prepare path and follow
- local currentWaypoints = {}
- local currentIndex = 1
- local lastPlayerPos = player.Character.PrimaryPart.Position
- local function refreshPath()
- local success, err = tryComputePath(NPC.PrimaryPart.Position, player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position)
- if not success then
- table.clear(currentWaypoints)
- return
- end
- currentWaypoints = path:GetWaypoints()
- currentIndex = 1
- end
- refreshPath()
- -- start chase animations/sounds
- runAnim:Play()
- if hrp:FindFirstChild("Scream") then hrp.Scream:Play() end
- if scp096Remote then scp096Remote:FireClient(player) end
- -- monitor player movement and refresh path if necessary
- local refreshTask = task.spawn(function()
- while targetedPlayer do
- if not player.Character or not player.Character.PrimaryPart then
- break
- end
- local curPos = player.Character.PrimaryPart.Position
- if (curPos - lastPlayerPos).Magnitude >= 2 then
- lastPlayerPos = curPos
- refreshPath()
- end
- task.wait(0.25)
- end
- end)
- -- follow current waypoints
- while targetedPlayer and currentIndex <= #currentWaypoints do
- if not player.Character or not player.Character.PrimaryPart or player.Character.Humanoid.Health <= 0 then
- break
- end
- humanoid.WalkSpeed = 35
- local wp = currentWaypoints[currentIndex]
- if wp and wp.Position then
- humanoid:MoveTo(wp.Position)
- humanoid.MoveToFinished:Wait()
- end
- currentIndex = currentIndex + 1
- end
- -- Kill player once the NPC has reached final waypoint
- -- 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
- if targetedPlayer and player.Character and player.Character.PrimaryPart and player.Character.Humanoid.Health > 0 then
- if hrp:FindFirstChild("Kill") then hrp.Kill:Play() end
- local particle = script:FindFirstChild("Particle")
- if particle and player.Character.PrimaryPart:FindFirstChild("RootAttachment") then
- local pClone = particle:Clone()
- pClone.Parent = player.Character.PrimaryPart.RootAttachment
- pClone:Emit(5)
- Debris:AddItem(pClone, 2)
- end
- if player.Character:FindFirstChild("Humanoid") then
- player.Character.Humanoid:TakeDamage(math.huge)
- end
- end
- targetedPlayer = nil
- runAnim:Stop()
- if hrp:FindFirstChild("Scream") then hrp.Scream:Stop() end
- humanoid.WalkSpeed = 8
- end
Advertisement
Add Comment
Please, Sign In to add comment