Advertisement
20CrackScratch08

Pathfinding with NPCS, with bubble chat

Apr 10th, 2022
1,410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.02 KB | None | 0 0
  1.  
  2. local StartPoints = {
  3.     Vector3.new(2.413, 63.404, -192.273),
  4.     Vector3.new(90, 59.124, -106.053),
  5.     Vector3.new(-89.773, 64.425, -103.589),
  6.     Vector3.new(87.907, 65.74, 13.814),
  7.     Vector3.new(-89.515, 66.008, 15.945),
  8.     Vector3.new(88.986, 64.027, 132.04),
  9.     Vector3.new(-90.259, 65.74, 134.974),
  10.     Vector3.new(60.493, 63.391, 190.158),
  11.     Vector3.new(-2.715, 65.74, 188.564),
  12.     Vector3.new(-61.894, 65.74, 190.386)
  13. }
  14.  
  15. local EndPoints = {
  16.     Vector3.new(8, 91, -486),
  17.     Vector3.new(388.82, 79.961, -106.486),
  18.     Vector3.new(-384.038, 91.046, -103.333),
  19.     Vector3.new(378.927, 77.956, 13.814),
  20.     Vector3.new(-385.485, 78.461, 17.784),
  21.     Vector3.new(389.247, 80.141, 131.679),
  22.     Vector3.new(-392.683, 82.294, 136.576),
  23.     Vector3.new(58.633, 78.845, 490.814),
  24.     Vector3.new(-1.732, 79.544, 492.335),
  25.     Vector3.new(-60.728, 85.767, 492.501)
  26. }
  27.  
  28. for i,v in pairs(StartPoints) do
  29.     local part = Instance.new("Part")
  30.     part.Parent = game:GetService("Workspace"):FindFirstChild("Points")
  31.     part.CanCollide = false
  32.     part.Transparency = 1
  33.     part.Name = "Start"..i
  34.     part.Position = v
  35.     part.Size = Vector3.new(1,1,1)
  36.     part.Anchored = true
  37. end
  38.  
  39. for i,v in pairs(EndPoints) do
  40.     local part = Instance.new("Part")
  41.     part.Parent = game:GetService("Workspace"):FindFirstChild("Points")
  42.     part.CanCollide = false
  43.     part.Transparency = 1
  44.     part.Name = "End"..i
  45.     part.Position = v
  46.     part.Size = Vector3.new(1,1,1)
  47.     part.Anchored = true
  48. end
  49.  
  50. while wait(2) do
  51.  
  52.     local Number = math.random(1, #StartPoints)
  53.     local PFS = game:GetService("PathfindingService")
  54.  
  55.     local hum = script.Parent:WaitForChild("Humanoid")
  56.     local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
  57.     hum.Parent.PrimaryPart:SetNetworkOwner(nil) -- change character to the variable that your npc is in.
  58.  
  59.     local GoingPath = PFS:CreatePath()
  60.     GoingPath:ComputeAsync(HumanoidRootPart.Position, game:GetService("Workspace"):WaitForChild("Points"):WaitForChild("Start"..Number).Position)
  61.     local GoingWaypoints = GoingPath:GetWaypoints()
  62.  
  63.     for i, waypoint in pairs(GoingWaypoints) do
  64.         if waypoint.Action == Enum.PathWaypointAction.Jump then
  65.             hum.Jump = true
  66.         end
  67.         --[[local part = Instance.new("Part")
  68.         part.Shape = "Ball"
  69.         part.Name = "Part"..i
  70.         part.CanCollide = false
  71.         part.Anchored = true
  72.         part.Parent = game.Workspace.Parts
  73.         part.Position = Vector3.new(waypoint.Position.X, waypoint.Position.Y + 2.5, waypoint.Position.Z)
  74.         part.Size = Vector3.new(0.5,0.5,0.5)
  75.         part.Transparency = 0.5
  76.         part.Color = Color3.fromHex("#FFFFFF")
  77.         part.Material = Enum.Material.Neon--]]
  78.     end
  79.  
  80.     for i, waypoint in pairs(GoingWaypoints) do
  81.         if waypoint.Action == Enum.PathWaypointAction.Jump then
  82.             hum:ChangeState(Enum.HumanoidStateType.Jumping)
  83.         end
  84.         hum:MoveTo(waypoint.Position)
  85.         hum.MoveToFinished:Wait(2)
  86.     end
  87.  
  88.     local path = PFS:CreatePath()
  89.     path:ComputeAsync(HumanoidRootPart.Position, game:GetService("Workspace"):WaitForChild("Points"):WaitForChild("End"..Number).Position)
  90.     local waypoints = path:GetWaypoints()
  91.  
  92.     for i, waypoint in pairs(waypoints) do
  93.         if waypoint.Action == Enum.PathWaypointAction.Jump then
  94.             hum.Jump = true
  95.         end
  96.         --[[local part = Instance.new("Part")
  97.         part.Shape = "Ball"
  98.         part.Name = "Part"..i
  99.         part.CanCollide = false
  100.         part.Anchored = true
  101.         part.Parent = game.Workspace.Parts
  102.         part.Position = Vector3.new(waypoint.Position.X, waypoint.Position.Y + 2.5, waypoint.Position.Z)
  103.         part.Size = Vector3.new(0.5,0.5,0.5)
  104.         part.Transparency = 0.5
  105.         part.Color = Color3.fromHex("#FFFFFF")
  106.         part.Material = Enum.Material.Neon--]]
  107.     end
  108.  
  109.     for i, waypoint in pairs(waypoints) do
  110.         if waypoint.Action == Enum.PathWaypointAction.Jump then
  111.             hum:ChangeState(Enum.HumanoidStateType.Jumping)
  112.         end
  113.         hum:MoveTo(waypoint.Position)
  114.         hum.MoveToFinished:Wait(2)
  115.     end
  116.  
  117.     local CommonTime = 0
  118.     local Obby = ""
  119.     if Number == 1 then
  120.         CommonTime = 16.7
  121.         Obby = "Original Timed Obby"
  122.     elseif Number == 2 then
  123.         CommonTime = 11.7
  124.         Obby = "Easy Timed Obby"
  125.     elseif Number == 3 then
  126.         CommonTime = 17
  127.         Obby = "Medium Timed Obby"
  128.     elseif Number == 4 then
  129.         CommonTime = 13
  130.         Obby = "Easy Killpart Obby"
  131.     elseif Number == 5 then
  132.         CommonTime = 16.5
  133.         Obby = "Medium Killpart Obby"
  134.     elseif Number == 6 then
  135.         CommonTime = 14.2
  136.         Obby = "Easy Wallhop Obby"
  137.     elseif Number == 7 then
  138.         CommonTime = 23
  139.         Obby = "Medium Wallhop Obby"
  140.     elseif Number == 8 then
  141.         CommonTime = 17.3
  142.         Obby = "Hard Timed Obby"
  143.     elseif Number == 9 then
  144.         CommonTime = 19.5
  145.         Obby = "Hard Killpart Obby"
  146.     elseif Number == 10 then
  147.         CommonTime = 23
  148.         Obby = "Hard Wallhop Obby"
  149.     end
  150.     local Time = math.random(CommonTime * 10 - 5, CommonTime * 10 + 5) / 10
  151.     local phrases = {
  152.         "Yay! I made "..Time.." at "..Obby,
  153.         "Let's go! I got "..Time.." on the "..Obby.."!"
  154.     }
  155.     local phrase = phrases[math.random(1, #phrases)]
  156.     local num = math.random(1,10)
  157.     local bchat = game:GetService("ReplicatedStorage"):WaitForChild("NpcBubbleChat"):Clone()
  158.     bchat.Parent = script.Parent.Head
  159.     bchat:WaitForChild("TextLabel").Text = phrase
  160.     print(num)
  161.     if num == 3 then
  162.         print("Good!")
  163.         game.ReplicatedStorage.RemoteEvents.NPCFinishValues.Phrase.Value = phrase
  164.         game.ReplicatedStorage.RemoteEvents.NPCFinishValues.NPCName.Value = script.Parent.Name
  165.         if game.ReplicatedStorage.RemoteEvents.NPCFinishValues.Update.Value then
  166.             game.ReplicatedStorage.RemoteEvents.NPCFinishValues.Update.Value = false
  167.         else
  168.             game.ReplicatedStorage.RemoteEvents.NPCFinishValues.Update.Value = true
  169.         end
  170.         while bchat:WaitForChild("TextLabel").TextTransparency > 0 do
  171.             bchat:WaitForChild("TextLabel").TextTransparency -= 0.1
  172.             bchat:WaitForChild("TextLabel").BackgroundTransparency -= 0.1
  173.             wait(0.05)
  174.         end
  175.     end    
  176.  
  177.     wait(3)
  178.     HumanoidRootPart.CFrame = game:GetService("Workspace"):WaitForChild("Points"):WaitForChild("Start"..Number).CFrame
  179.     wait(1)
  180.     if num == 3 then
  181.         while bchat:WaitForChild("TextLabel").TextTransparency < 1 do
  182.             bchat:WaitForChild("TextLabel").TextTransparency += 0.1
  183.             bchat:WaitForChild("TextLabel").BackgroundTransparency += 0.1
  184.             wait(0.05)
  185.         end
  186.     end
  187.     bchat:Destroy()
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement