Advertisement
MandB

Good Jumpscare

Aug 25th, 2021
3,876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.54 KB | None | 0 0
  1. --UperTorsoScript
  2.  
  3. function onTouched(part)
  4.  
  5. local h = part.Parent:findFirstChild("Humanoid")
  6.  
  7. if h~=nil then
  8.  
  9. h.Health = h.Health - 1
  10.  
  11. end
  12.  
  13. end
  14.  
  15.  
  16.  
  17. script.Parent.Touched:connect(onTouched)
  18.  
  19. --LowerTorsoScript
  20.  
  21. local jumpscareModule = require(game.ReplicatedStorage:WaitForChild("Modules"):WaitForChild("Jumpscare Manager"))
  22. local debounces = { }
  23. local Players = game:GetService("Players")
  24.  
  25. script.Parent.Touched:connect(function(hit)
  26. local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  27.  
  28. if debounces[player] then
  29. return -- If their debounce is still active then return
  30. end
  31.  
  32. debounces[player] = true
  33. jumpscareModule.Jumpscare(player)
  34. wait(4)
  35. debounces[player] = nil
  36. end)
  37.  
  38. --RagdollR15Script
  39.  
  40. local character = script.Parent
  41.  
  42. function recurse(root,callback,i)
  43. i= i or 0
  44. for _,v in pairs(root:GetChildren()) do
  45. i = i + 1
  46. callback(i,v)
  47.  
  48. if #v:GetChildren() > 0 then
  49. i = recurse(v,callback,i)
  50. end
  51. end
  52.  
  53. return i
  54. end
  55.  
  56. function ragdollJoint(part0, part1, attachmentName, className, properties)
  57. attachmentName = attachmentName.."RigAttachment"
  58. local constraint = Instance.new(className.."Constraint")
  59. constraint.Attachment0 = part0:FindFirstChild(attachmentName)
  60. constraint.Attachment1 = part1:FindFirstChild(attachmentName)
  61. constraint.Name = "RagdollConstraint"..part1.Name
  62.  
  63. for _,propertyData in next,properties or {} do
  64. constraint[propertyData[1]] = propertyData[2]
  65. end
  66.  
  67. constraint.Parent = character
  68. end
  69.  
  70. function getAttachment0(attachmentName)
  71. for _,child in next,character:GetChildren() do
  72. local attachment = child:FindFirstChild(attachmentName)
  73. if attachment then
  74. return attachment
  75. end
  76. end
  77. end
  78.  
  79. character:WaitForChild("Humanoid").Died:connect(function()
  80. local camera = workspace.CurrentCamera
  81. if camera.CameraSubject == character.Humanoid then--If developer isn't controlling camera
  82. camera.CameraSubject = character.UpperTorso
  83. end
  84.  
  85. --Make it so ragdoll can't collide with invisible HRP, but don't let HRP fall through map and be destroyed in process
  86. character.HumanoidRootPart.Anchored = true
  87. character.HumanoidRootPart.CanCollide = false
  88.  
  89. --Helps to fix constraint spasms
  90. recurse(character, function(_,v)
  91. if v:IsA("Attachment") then
  92. v.Axis = Vector3.new(0, 1, 0)
  93. v.SecondaryAxis = Vector3.new(0, 0, 1)
  94. v.Rotation = Vector3.new(0, 0, 0)
  95. end
  96. end)
  97.  
  98. --Re-attach hats
  99. for _,child in next,character:GetChildren() do
  100. if child:IsA("Accoutrement") then
  101. --Loop through all parts instead of only checking for one to be forwards-compatible in the event
  102. --ROBLOX implements multi-part accessories
  103. for _,part in next,child:GetChildren() do
  104. if part:IsA("BasePart") then
  105. local attachment1 = part:FindFirstChildOfClass("Attachment")
  106. local attachment0 = getAttachment0(attachment1.Name)
  107. if attachment0 and attachment1 then
  108. --Shouldn't use constraints for this, but have to because of a ROBLOX idiosyncrasy where
  109. --joints connecting a character are perpetually deleted while the character is dead
  110. local constraint = Instance.new("HingeConstraint")
  111. constraint.Attachment0 = attachment0
  112. constraint.Attachment1 = attachment1
  113. constraint.LimitsEnabled = true
  114. constraint.UpperAngle = 0 --Simulate weld by making it difficult for constraint to move
  115. constraint.LowerAngle = 0
  116. constraint.Parent = character
  117. end
  118. end
  119. end
  120. end
  121. end
  122.  
  123. ragdollJoint(character.LowerTorso, character.UpperTorso, "Waist", "BallSocket", {
  124. {"LimitsEnabled",true};
  125. {"UpperAngle",5};
  126. })
  127. ragdollJoint(character.UpperTorso, character.Head, "Neck", "BallSocket", {
  128. {"LimitsEnabled",true};
  129. {"UpperAngle",15};
  130. })
  131.  
  132. local handProperties = {
  133. {"LimitsEnabled", true};
  134. {"UpperAngle",0};
  135. {"LowerAngle",0};
  136. }
  137. ragdollJoint(character.LeftLowerArm, character.LeftHand, "LeftWrist", "Hinge", handProperties)
  138. ragdollJoint(character.RightLowerArm, character.RightHand, "RightWrist", "Hinge", handProperties)
  139.  
  140. local shinProperties = {
  141. {"LimitsEnabled", true};
  142. {"UpperAngle", 0};
  143. {"LowerAngle", -75};
  144. }
  145. ragdollJoint(character.LeftUpperLeg, character.LeftLowerLeg, "LeftKnee", "Hinge", shinProperties)
  146. ragdollJoint(character.RightUpperLeg, character.RightLowerLeg, "RightKnee", "Hinge", shinProperties)
  147.  
  148. local footProperties = {
  149. {"LimitsEnabled", true};
  150. {"UpperAngle", 15};
  151. {"LowerAngle", -45};
  152. }
  153. ragdollJoint(character.LeftLowerLeg, character.LeftFoot, "LeftAnkle", "Hinge", footProperties)
  154. ragdollJoint(character.RightLowerLeg, character.RightFoot, "RightAnkle", "Hinge", footProperties)
  155.  
  156. --TODO fix ability for socket to turn backwards whenn ConeConstraints are shipped
  157. ragdollJoint(character.UpperTorso, character.LeftUpperArm, "LeftShoulder", "BallSocket")
  158. ragdollJoint(character.LeftUpperArm, character.LeftLowerArm, "LeftElbow", "BallSocket")
  159. ragdollJoint(character.UpperTorso, character.RightUpperArm, "RightShoulder", "BallSocket")
  160. ragdollJoint(character.RightUpperArm, character.RightLowerArm, "RightElbow", "BallSocket")
  161. ragdollJoint(character.LowerTorso, character.LeftUpperLeg, "LeftHip", "BallSocket")
  162. ragdollJoint(character.LowerTorso, character.RightUpperLeg, "RightHip", "BallSocket")
  163. end)
  164.  
  165. --RespawnScript
  166.  
  167. name="Humanoid"
  168.  
  169. robo=script.Parent:clone()
  170.  
  171. while true do
  172. wait(5)
  173. if script.Parent.Humanoid.Health<1 then
  174. robot=robo:clone()
  175. robot.Parent=script.Parent.Parent
  176. robot:makeJoints()
  177. script.Parent:remove()
  178. end
  179. end
  180.  
  181.  
  182.  
  183. --AiScript
  184.  
  185. --Beta SpeedAI June 2012 -- Still has logic bugs - Look for updates..
  186. -- Kill added.
  187. -- co-operate/other "AI"s
  188. -- Climb "Truss" Parts
  189. -- Offset Ray
  190. -- Swim - Does not work. Don't know why.
  191. -- Adjusted Jump Ray
  192. -- Ray Graphics On/Off - flip line 90
  193. -- Delay next cycle, if Falling.
  194. -- Diagonal movement - I should add right-hand logic as well...
  195.  
  196. local number = 1 + math.random()
  197. local BRAINWave = .6 -- AND line 38: Wait() between cycles of main loop
  198. local hum = nil -- Will be a pointer to the Humanoid of our AI.
  199.  
  200. wait(number) -- hold on a sec. and spread multiple instances.
  201.  
  202. --Globals
  203. local AI = script.Parent
  204. local AIName = AI.Name
  205. local AItorso = AI.UpperTorso
  206.  
  207.  
  208. if true then -- if your torso doesn't have a Humanoid; flip this to false
  209. local HumanoidType = nil -- find-a-HumanoidObject -- make sure
  210.  
  211. local list = AI:GetChildren() -- temp var.
  212. for x = 1, #list do
  213. local temp = list[x]
  214. if (temp.className == "Humanoid") then
  215. HumanoidType = temp.Name
  216. end -- found Humanoid
  217. end -- AI Parts
  218.  
  219. if HumanoidType then
  220. number = math.floor(number*100) -- serial# of AI
  221. hum = AI[HumanoidType]
  222. BRAINWave = 7/hum.WalkSpeed -- For extreme speeds, this may have to be adjusted.
  223. print (script, ": Humanoid = ", hum, AI:GetFullName(), number, "- Think Speed = ", BRAINWave)
  224. end
  225. end -- set speed
  226.  
  227. --Constants;
  228. local RAYLength = 100 -- Not really. A point, off in space.
  229.  
  230. --Declarations
  231. local target = AItorso -- is of type torso
  232. local torsoPos = AItorso.Position
  233. local targpos = target.Position
  234. --local Oldtargpos = targpos
  235.  
  236. local OldPos = torsoPos * 2
  237. local origin = CFrame.new(torsoPos)
  238.  
  239. local Logic = 0
  240. local OldX = 100
  241. local OldZ = 0
  242. local Xdir = 100
  243. local Zdir = 0
  244. local ClimbingLadder = false
  245. local FreeFalling = false
  246. local GraphicsOn = script.GraphicsToggle.Value -- Only set at start
  247.  
  248. --functions
  249.  
  250. -- Are we falling?
  251. hum.FreeFalling:connect(function()
  252. FreeFalling = true
  253. end)
  254.  
  255. -- Find Player (& who else not to find).
  256. function findNearestTorso(pos) -- declare pos a local vector3
  257. local list = game.Workspace:children()
  258. local torso = nil
  259. local dist = 100000 -- Area to search
  260. local temp = nil
  261. local human = nil
  262. local temp2 = nil
  263. for x = 1, #list do
  264. temp2 = list[x]
  265. if temp2.className == "Model" then
  266. temp = temp2:findFirstChild("UpperTorso")
  267. if temp ~= nil then
  268. human = temp2:findFirstChild("Humanoid")
  269. if human ~= nil and (human.Health > 0) and (temp2.Name ~= AIName) then -- not named the same as us.
  270. if (temp.Position - pos).magnitude < dist then
  271. torso = temp
  272. dist = (temp.Position - pos).magnitude
  273. end -- closer?
  274. end -- human? Not us.
  275. end -- Has torso?
  276. end -- Model?
  277. end -- For. Loop thru parts in Workplace
  278.  
  279. return torso
  280. end -- findNearest
  281.  
  282.  
  283. function DrawRay(origin, point) -- 7 studs long
  284. local Ray = Ray.new(origin, (point).unit * 7) --Make the ray.
  285. local Hit,Position = game.Workspace:FindPartOnRay(Ray,AI) --Check for collisions along the ray, ignoring any Parts of us.
  286.  
  287. if GraphicsOn then --Graphics
  288. local RayPart = Instance.new("Part",AI)
  289. if Hit then
  290. if Logic == 1 then
  291. RayPart.BrickColor = BrickColor.new("Black") --Set its color.
  292. else
  293. RayPart.BrickColor = BrickColor.new("Bright red") --Set its color.
  294. end
  295. else
  296. if Logic == 1 then
  297. RayPart.BrickColor = BrickColor.new("White") --Set its color.
  298. else
  299. RayPart.BrickColor = BrickColor.new("Olive") --Set its color.
  300. end
  301. end
  302. RayPart.Transparency = 0.2 --Set its transparency.
  303. RayPart.Anchored = true --Set whether it will fall or not.
  304. RayPart.CanCollide = false --Set whether people can walk though it or not.
  305. RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
  306. local Distance = (Position-origin).magnitude --Find the distance between the hit and the torso.
  307. RayPart.Size = Vector3.new(0.4,.2,Distance) --Set its size to the distance.
  308. RayPart.CFrame = CFrame.new(Position, origin) * CFrame.new(0,0,-Distance/2) --Move it halfway.
  309. game.Debris:AddItem(RayPart,2) --Add it to the debris.
  310. end -- Graphics
  311.  
  312. return Hit
  313. end -- DrawRay
  314.  
  315.  
  316. function FireRayToward() -- possible path, and read the Part we hit, if any.
  317. ClimbingLadder = false
  318.  
  319. local originPrime = origin * Vector3.new(.8,0,0) - Vector3.new(0,.4,0) -- Offset Right + OffY
  320. local offset = origin * Vector3.new(.8,0,0) - origin * Vector3.new(-.8,0,0) -- left (I guess this is increment. I didn't WANT to do it this way)
  321. local point = origin.lookVector * 7 -- dir
  322. local pointPrime = point - offset + Vector3.new(0,2,0) -- dir + OffsetLeft + OffsetY = direction of Ray
  323.  
  324. local Hit = DrawRay(originPrime, pointPrime) -- see if we hit anything
  325.  
  326. if Hit then
  327.  
  328. if target.Parent == Hit.Parent then
  329. -- AI.Head:BreakJoints()
  330. if Hit.Name ~= "UpperTorso" and Hit.Name ~= "Head" then
  331. Hit:BreakJoints()
  332. Hit.CanCollide = true
  333. else
  334. Hit.Parent.Humanoid:TakeDamage(84)
  335. end -- kill
  336.  
  337. Logic = 0
  338. Hit = nil
  339.  
  340. elseif Hit.Parent.Name == AIName then
  341. -- if Xdir > 0 then -- if going ?North? then ignore, else (?South?); Jump
  342. -- Hit = nil -- ignore
  343. -- elseif Xdir == 0 then -- else swerve (only while in logic).
  344. if Xdir == 0 then
  345. Hit = Aitorso-- this should result in Hit = true-but-don't-attemp-a-jump, so swerve; doesn't check floor!
  346. -- return hit -- Swerve, without checking to jump.
  347. elseif Hit.Velocity.y > 1 then
  348. Hit = nil -- ignore, if other AI is already jumping; else check to Jump
  349. end -- East -West collisions - swerve. North/South, check-to-jump.
  350. end -- endifs
  351. end -- read hit
  352.  
  353. -- Climb or Jump
  354. if Hit and Hit ~= AItorso then
  355.  
  356. if (Hit.Name == "Truss" and target.Position.y > torsoPos.y - 3) or target.Parent == Hit.Parent then -- ignore parts called "Ladder", if AI is level or below CURRENT Targ pos.
  357. Hit = nil
  358. ClimbingLadder = true -- Climb and don't check floor
  359.  
  360. else
  361. --print(Hit, Hit.Name)
  362. if Hit.Name == "Terrain" or Hit.CanCollide == false then -- In front is Water or a steep hill made of Terrain.
  363. Hit = nil -- swim or climb, or Ray hit a Non-colliding Part; and don't check for floor. This will not do, as we do not get a Hit when under-water, so we will check for floor. We must check Swimming event.
  364. else -- Jump?
  365. Hit = DrawRay(originPrime + Vector3.new(0,4.8,0), pointPrime)
  366. if Hit == nil then -- (Does NOT check CanCollide of Part blocking Jump)
  367. hum.Jump = true -- we do NOT check for "Floor", if jumping, but it might be a good idea.
  368. end -- Room to jump?
  369. end --Terrain? Water?
  370. end -- Ladder?
  371.  
  372. else -- path is clear. Check for cliff... or OK to drop
  373.  
  374. local Level = torsoPos.y
  375. if target then
  376. Level = target.Position.y -- get Target's current position.
  377. else -- Target is dead. Abandon all logic...
  378. Logic = 0 -- but still check for floor
  379. end
  380.  
  381. if torsoPos.y - 2 < Level then -- if Player is not well below us...
  382.  
  383. Hit = DrawRay(torsoPos + point * .8 + Vector3.new(0,1,0), Vector3.new(0,-7,0)) -- check for floor 85% of dir ahead
  384. if Hit == nil then -- There is no floor
  385. Hit = true -- Force a hit; we may not be able to get back up here.
  386.  
  387. else
  388. Hit = nil -- Force a false to hit, 'cause everything is OK. (Does NOT check CanCollide of Floor!)
  389. end -- cliff check
  390. end -- Player Hieght
  391. end -- path ok?
  392. return Hit
  393. end -- FireRayToward
  394.  
  395.  
  396. function FireAtPlayer()
  397. origin = CFrame.new(torsoPos, Vector3.new(targpos.x, torsoPos.y, targpos.z)) -- This contains Origin & Direction
  398. local hit = FireRayToward()
  399. return hit
  400. end
  401.  
  402. function FireRayAhead()
  403. origin = CFrame.new(torsoPos, torsoPos + Vector3.new(Xdir, 0, Zdir))
  404. local hit = FireRayToward()
  405. targpos = torsoPos + Vector3.new(Xdir,0,Zdir)
  406. return hit
  407. end
  408.  
  409. function FireRay() -- Fire Ahead and diagonaly
  410. origin = CFrame.new(torsoPos, torsoPos + Vector3.new(Xdag, 0, Zdag))
  411. local hit = FireRayToward()
  412. if hit then
  413. origin = CFrame.new(torsoPos, torsoPos + Vector3.new(Xdir, 0, Zdir))
  414. hit = FireRayToward()
  415. if not hit then
  416. targpos = torsoPos + Vector3.new(Xdir,0,Zdir)
  417. end
  418. else
  419. targpos = torsoPos + Vector3.new(Xdag,0,Zdag)
  420. end
  421. return hit
  422. end -- Fire Ray
  423.  
  424. function FireDag()
  425. origin = CFrame.new(torsoPos, torsoPos + Vector3.new(Xdag, 0, Zdag))
  426. local hit = FireRayToward()
  427. return hit
  428. end -- Fire Diagonaly
  429.  
  430.  
  431. function TurnRight()
  432.  
  433. if Xdir == 0 then
  434. Xdir = -Zdir
  435. Zdir = 0
  436. else
  437. Zdir = Xdir
  438. Xdir = 0
  439. end
  440. if Xdag == Zdag then Xdag = -Xdag else Zdag = -Zdag end
  441.  
  442. end -- Left
  443.  
  444. function TurnLeft()
  445. if Xdir == 0 then
  446. Xdir = Zdir
  447. Zdir = 0
  448. else
  449. Zdir = -Xdir
  450. Xdir = 0
  451. end
  452.  
  453. if Xdag == Zdag then Zdag = -Zdag else Xdag = -Xdag end
  454.  
  455. end -- Left
  456.  
  457.  
  458. function GetDir()
  459. Xdir = (targpos.x - torsoPos.x) -- Which way are we going?
  460. Zdir = (targpos.z - torsoPos.z)
  461.  
  462. -- if Zdir < 0 then -- Get closest 45 degree angle. Diagonal.
  463. -- Zdag = -RAYLength
  464. -- else
  465. -- Zdag = RAYLength
  466. -- end
  467. -- if Xdir < 0 then
  468. -- Xdag = -RAYLength
  469. -- else
  470. -- Xdag = RAYLength
  471. -- end
  472.  
  473. if math.abs(Xdir) > math.abs(Zdir) then -- Ordinal.
  474. if Xdir < 0 then
  475. Xdir = -RAYLength
  476. -- convert to our direction indicator.
  477. else
  478. Xdir = RAYLength
  479. end
  480. Zdag = Xdir -- Diagonal Right.
  481. Xdag = Xdir
  482. Zdir = 0
  483. else -- abs
  484. if Zdir < 0 then
  485. Zdir = -RAYLength
  486. else
  487. Zdir = RAYLength
  488. end
  489. Zdag = Zdir
  490. Xdag = -Zdir
  491. Xdir = 0
  492. end -- abs
  493. end -- GetDir
  494.  
  495.  
  496. while AItorso do -- while I still have a body; search.
  497. torsoPos = AItorso.Position
  498. local targ = workspace.Terrain -- Temp targ
  499. local Distance =(torsoPos - OldPos).magnitude -- Distance traveled, since last loop
  500. --local Distance =10
  501. if target == nil then Logic = 0
  502. -- Distance = 10
  503. end -- Player died.
  504.  
  505.  
  506. if Logic == 0 then -- Defalt logic
  507.  
  508. target = findNearestTorso(torsoPos) --- target is some Player. FindNearest and get xdir, ydir.
  509.  
  510. if target ~= nil then
  511. targ = target
  512. -- if ClimbingLadder and Distance >= 1 then
  513. -- targpos = torsoPos + AItorso.CFrame.lookVector * 9
  514. -- else
  515. targpos = target.Position
  516. -- end
  517.  
  518. if Distance < 1 and (torsoPos - targpos).magnitude > 4 then -- Check if we are stuck.
  519. GetDir()
  520. OldX = Xdir -- Goal direction.
  521. OldZ = Zdir
  522.  
  523. Logic = 1 -- Impeded
  524.  
  525. else
  526. if FireAtPlayer() then -- hit
  527.  
  528. GetDir()
  529. OldX = Xdir -- Goal direction.
  530. OldZ = Zdir
  531.  
  532. if FireDag() then
  533. Logic = 1 -- Go Left; Look Right.
  534. ClimbingLadder = true -- first time thru logic 1 indicator
  535. else
  536. targpos = torsoPos + Vector3.new(Xdag,0,Zdag) -- go Right
  537.  
  538. end -- dagRight
  539. end -- hit?
  540. end -- impeded?
  541. else
  542. print(AIName, number, ": No target. - ", target)
  543. -- torsoPos = torsoPos * 2 -- Turn Impeded?, off
  544. -- Distance = 10
  545. end -- if no target?
  546. end -- Logic 0
  547.  
  548.  
  549. -- 1 - Look Right or Go left
  550. if Logic == 1 then
  551.  
  552. if Distance >= 1 then
  553. if ClimbingLadder == false then -- or target.Position.y < torsoPos.y + 4 then
  554. TurnRight()
  555. end -- else go straight or go up
  556. else
  557. TurnLeft()
  558. end
  559.  
  560. if FireRayAhead() then -- Check straight first. (And Diagonaly left)
  561. TurnLeft()
  562. if FireRay() then -- Check left (And Diagonaly left & back)
  563. TurnLeft()
  564. if FireRay() then
  565. TurnLeft()
  566. if FireRay() then
  567. targpos = torsoPos + Vector3.new(Xdir,0,Zdir)
  568. hum.Jump = true
  569. end -- right
  570. end -- Back
  571. end -- Left
  572. else -- If succesful Ahead then... (We only check RightTurns for a get-out-of-jail-Free card)
  573.  
  574. if Xdir == OldX and OldZ == Zdir then -- Gracefully exiting Logic 1
  575. Logic = 0
  576. end -- check Goal dir?
  577. end -- Ahead
  578. end -- Logic 1
  579.  
  580. -- go
  581. OldPos = torsoPos
  582. hum:MoveTo(targpos, targ) -- MoveToward Target
  583.  
  584. --wait
  585. wait(BRAINWave)
  586.  
  587. while FreeFalling do
  588. FreeFalling = false
  589. wait(.2)
  590. end
  591.  
  592. end -- Main
  593.  
  594. --WeaponFiringScript
  595.  
  596. local target = script.Parent:WaitForChild("Target")
  597. local torso = script.Parent.Parent:WaitForChild("Torso")
  598. local down = script.Parent:WaitForChild("MouseDown")
  599.  
  600. function handler(new)
  601. if target.Value then
  602. while target.Value == new do
  603. if target.Value and target.Value.Parent == nil then
  604. target.Value = nil
  605. return
  606. end
  607. local look = (new.Torso.Position-torso.Position).unit * 300
  608. local hit = workspace:FindPartOnRayWithIgnoreList(Ray.new(torso.Position,look),{script.Parent.Parent,new.Parent})
  609. if not hit or (new.Torso.Position-torso.Position).magnitude < 10 then
  610. down:Fire(new.Torso.Position)
  611. end
  612. wait(0.2)
  613. end
  614. end
  615. end
  616.  
  617. target.Changed:connect(handler)
  618.  
  619. if target.Value then
  620. handler(target.Value)
  621. end
  622.  
  623. --PathFindongScript
  624.  
  625. debugMode = false
  626. targetNPCs = false
  627.  
  628. --
  629.  
  630. h = script.Parent.Parent:WaitForChild("Humanoid")
  631. pathService = game:GetService("PathfindingService")
  632. targetV = script.Parent:WaitForChild("Target")
  633.  
  634. function closestTargetAndPath()
  635. local humanoids = {}
  636. if targetNPCs then
  637. local function recurse(o)
  638. for _,obj in pairs(o:GetChildren()) do
  639. if obj:IsA("Model") then
  640. if obj:findFirstChild("Humanoid") and obj:findFirstChild("Torso") and obj.Humanoid ~= h and obj.Humanoid.Health > 0 and not obj:findFirstChild("ForceField") then
  641. table.insert(humanoids,obj.Humanoid)
  642. end
  643. end
  644. recurse(obj)
  645. end
  646. end
  647. recurse(workspace)
  648. else
  649. for _,v in pairs(game.Players:GetPlayers()) do
  650. if v.Character and v.Character:findFirstChild("HumanoidRootPart") and v.Character:findFirstChild("Humanoid") and v.Character.Humanoid.Health > 0 and not v:findFirstChild("ForceField") then
  651. table.insert(humanoids,v.Character.Humanoid)
  652. end
  653. end
  654. end
  655. local closest,path,dist
  656. for _,humanoid in pairs(humanoids) do
  657. local myPath = pathService:ComputeRawPathAsync(h.Torso.Position,humanoid.Torso.Position,500)
  658. if myPath.Status ~= Enum.PathStatus.FailFinishNotEmpty then
  659. -- Now that we have a successful path, we need to figure out how far we need to actually travel to reach this point.
  660. local myDist = 0
  661. local previous = h.Torso.Position
  662. for _,point in pairs(myPath:GetPointCoordinates()) do
  663. myDist = myDist + (point-previous).magnitude
  664. previous = point
  665. end
  666. if not dist or myDist < dist then -- if true, this is the closest path so far.
  667. closest = humanoid
  668. path = myPath
  669. dist = myDist
  670. end
  671. end
  672. end
  673. return closest,path
  674. end
  675.  
  676. function goToPos(loc)
  677. h:MoveTo(loc)
  678. local distance = (loc-h.Torso.Position).magnitude
  679. local start = tick()
  680. while distance > 4 do
  681. if tick()-start > distance/h.WalkSpeed then -- Something may have gone wrong. Just break.
  682. break
  683. end
  684. distance = (loc-h.Torso.Position).magnitude
  685. wait()
  686. end
  687. end
  688.  
  689. while wait() do
  690. local target,path = closestTargetAndPath()
  691. local didBreak = false
  692. local targetStart
  693. if target and h.Torso then
  694. targetV.Value = target
  695. targetStart = target.Torso.Position
  696. roaming = false
  697. local previous = h.Torso.Position
  698. local points = path:GetPointCoordinates()
  699. local s = #points > 1 and 2 or 1
  700. for i = s,#points do
  701. local point = points[i]
  702. if didBreak then
  703. break
  704. end
  705. if target and target.Torso and target.Health > 0 then
  706. if (target.Torso.Position-targetStart).magnitude < 1.5 then
  707. local pos = previous:lerp(point,.5)
  708. local moveDir = ((pos - h.Torso.Position).unit * 2)
  709. goToPos(previous:lerp(point,.5))
  710. previous = point
  711. end
  712. else
  713. didBreak = true
  714. break
  715. end
  716. end
  717. else
  718. targetV.Value = nil
  719. end
  720. if not didBreak and targetStart then
  721. goToPos(targetStart)
  722. end
  723. end
  724.  
  725. --JumpscareLocaly
  726.  
  727. local jumpscareModule = require(game.ReplicatedStorage:WaitForChild("Modules"):WaitForChild("Jumpscare Manager"))
  728. local jumpscareRemote = game.ReplicatedStorage:WaitForChild("Modules"):WaitForChild("Jumpscare Manager"):WaitForChild("Activate Jumpscare")
  729.  
  730. jumpscareRemote.OnServerEvent:Connect(function(player)
  731. jumpscareModule.Jumpscare(player)
  732. end)
  733.  
  734. --JumpscareManagerScript
  735.  
  736. local module = {
  737.  
  738. Animation = script.Animation;
  739. Duration = 0.6;
  740. Camera = workspace.Cameras.JumpscareCamera;
  741. DieAfter = true
  742.  
  743.  
  744. }
  745.  
  746. function module.Jumpscare(player)
  747. local camRemote = player.PlayerGui.ChangeCamera
  748. camRemote:FireClient(player,module.Camera)
  749.  
  750. local JumpscareDummy = workspace.JumpscareDummy
  751. local dummyHum = JumpscareDummy.Humanoid
  752. local scare = JumpscareDummy.Head.scarysound
  753.  
  754. dummyHum:LoadAnimation(module.Animation):Play()
  755. scare:Play()
  756.  
  757. wait(module.Duration)
  758. if module.DieAfter then
  759. player.Character:BreakJoints()
  760. end
  761. end
  762.  
  763. return module
  764.  
  765. --CameraScript
  766.  
  767. local camera = workspace.CurrentCamera
  768. local player = game.Players.LocalPlayer
  769. local character = player.Character or player:CharacterAdded()
  770.  
  771. script.Parent.OnClientEvent:Connect(function(camera2,duration)
  772. camera.CameraType = "Scriptable"
  773. camera.CFrame = camera2.CFrame
  774. end)
  775.  
  776. character:WaitForChild("Humanoid").Died:Connect(function()
  777. wait(1)
  778. camera.CameraSubject = character:WaitForChild("Humanoid")
  779. camera.CameraType = "Custom"
  780. camera.CFrame = character.Head.CFrame
  781. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement