Advertisement
fishinthebox

Untitled

Jul 20th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. local animtation = Instance.new("Animation")
  4.  
  5. animtation.AnimationId = "rbxassetid://18571207340"
  6.  
  7. local animationTrack = script.Parent.Humanoid.Animator:LoadAnimation(animtation)
  8.  
  9. print("script began")
  10.  
  11. local part = workspace.Enemies["sniper kids"].HumanoidRootPart
  12.  
  13. --local excludeTable = {script.Parent.Parent, workspace.Baseplate, workspace.Truss}
  14.  
  15. local maxDistance = 100_000
  16.  
  17. while true do
  18.     wait(5)
  19.     local nearestPlayer, nearestDistance
  20.     for _, player in pairs(Players:GetPlayers()) do
  21.         local character = player.Character
  22.         if not character then
  23.             continue
  24.         end
  25.         local distance = player:DistanceFromCharacter(part.Position)
  26.         if distance > maxDistance or (nearestDistance and distance >= nearestDistance) then
  27.             continue
  28.         end
  29.         nearestDistance = distance
  30.         nearestPlayer = player
  31.         print(nearestPlayer)
  32.     end
  33.  
  34.     if nearestPlayer and nearestPlayer.Character then
  35.         local nearestPlayerPos = nearestPlayer.Character.HumanoidRootPart.Position
  36.  
  37.         local direction = (nearestPlayerPos - part.Position).Unit * maxDistance
  38.        
  39.         local raycastParams = RaycastParams.new()
  40.         raycastParams.FilterType = Enum.RaycastFilterType.Exclude
  41.         raycastParams.FilterDescendantsInstances = {script.Parent.Parent, workspace.Baseplate, workspace.Truss} -- also put map later
  42.         raycastParams.IgnoreWater = true
  43.        
  44.         local raycastResult = workspace:Raycast(part.Position, direction, raycastParams)
  45.        
  46.         print(raycastParams)
  47.  
  48.         if raycastResult then
  49.             if raycastResult.Instance then
  50.                 print(excludeTable)
  51.                 print("there was a thing")
  52.                 local hitPartName = raycastResult.Instance.Name
  53.                 if hitPartName == "Head" or hitPartName == "Torso" or hitPartName == "Left Arm" or hitPartName == "Right Arm" or hitPartName == "Left Leg" or hitPartName == "Right Leg" or hitPartName == "HumanoidRootPart" and raycastResult.Instance.Parent.Parent == Players then
  54.                     print(hitPartName, ", did Hit player")
  55.                     animationTrack:Play()
  56.                     wait(0.3333333333333333333333)
  57.                     animationTrack:Stop()
  58.                 else
  59.                     print(hitPartName, ", did not hit player")
  60.                 end
  61.             else
  62.                 print("No Instance")
  63.             end
  64.         else
  65.             print("No Result")
  66.         end
  67.     end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement