Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - local Players = game:GetService("Players")
 - local animtation = Instance.new("Animation")
 - animtation.AnimationId = "rbxassetid://18571207340"
 - local animationTrack = script.Parent.Humanoid.Animator:LoadAnimation(animtation)
 - print("script began")
 - local part = workspace.Enemies["sniper kids"].HumanoidRootPart
 - --local excludeTable = {script.Parent.Parent, workspace.Baseplate, workspace.Truss}
 - local maxDistance = 100_000
 - while true do
 - wait(5)
 - local nearestPlayer, nearestDistance
 - for _, player in pairs(Players:GetPlayers()) do
 - local character = player.Character
 - if not character then
 - continue
 - end
 - local distance = player:DistanceFromCharacter(part.Position)
 - if distance > maxDistance or (nearestDistance and distance >= nearestDistance) then
 - continue
 - end
 - nearestDistance = distance
 - nearestPlayer = player
 - print(nearestPlayer)
 - end
 - if nearestPlayer and nearestPlayer.Character then
 - local nearestPlayerPos = nearestPlayer.Character.HumanoidRootPart.Position
 - local direction = (nearestPlayerPos - part.Position).Unit * maxDistance
 - local raycastParams = RaycastParams.new()
 - raycastParams.FilterType = Enum.RaycastFilterType.Exclude
 - raycastParams.FilterDescendantsInstances = {script.Parent.Parent, workspace.Baseplate, workspace.Truss} -- also put map later
 - raycastParams.IgnoreWater = true
 - local raycastResult = workspace:Raycast(part.Position, direction, raycastParams)
 - print(raycastParams)
 - if raycastResult then
 - if raycastResult.Instance then
 - print(excludeTable)
 - print("there was a thing")
 - local hitPartName = raycastResult.Instance.Name
 - 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
 - print(hitPartName, ", did Hit player")
 - animationTrack:Play()
 - wait(0.3333333333333333333333)
 - animationTrack:Stop()
 - else
 - print(hitPartName, ", did not hit player")
 - end
 - else
 - print("No Instance")
 - end
 - else
 - print("No Result")
 - end
 - end
 - end
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment