Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tweenservice = game:GetService("TweenService")
- local Gun = script.Parent.Gun
- local debrisservice = game:GetService("Debris")
- local Bullet = game:GetService("ServerStorage").Bullet
- local Light = script.Parent.Gun.Light
- local dist = 100
- local Targets = {}
- function compare(a,b)
- return a[2] < b[2]
- end
- function Fire(Human, Distance)
- local Bullet = game.ServerStorage.Bullet:Clone()
- Bullet.Parent = script.Parent.Debris
- Bullet.Size = Vector3.new(0.1, 0.1, 2)
- Bullet.BrickColor = BrickColor.new("New Yeller")
- Bullet.Anchored = true
- Bullet.CanCollide = false
- Bullet.Material = Enum.Material.Neon
- Bullet.Transparency = 0.7
- Bullet.Position = Gun.Position
- Bullet.CFrame = CFrame.new(Gun.Position,Human.Head.Position)
- local bullettween = tweenservice:Create(Bullet,TweenInfo.new(Distance/200,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0,false, 0), {CFrame = Gun.CFrame:ToWorldSpace(CFrame.new(0,0,-(Distance - Bullet.Size.Z/2)))})
- bullettween:Play()
- bullettween:Destroy()
- debrisservice:AddItem(Bullet,Distance/200)
- end
- function FindTarget()
- for i = 1,#Targets do
- table.remove(Targets,i)
- end
- for i,v in pairs(workspace:GetDescendants())do
- if v.Name == "Head" and v.Parent:FindFirstChild("Humanoid") then
- if v.Parent.Humanoid.Health > 0 then
- local ray = Ray.new(Gun.Position, (v.Position - Gun.Position).Unit *dist)
- local Part = workspace:FindPartOnRay(ray)
- if Part then
- if Part:IsDescendantOf(v.Parent) or Part.Name == "Bullet" then
- table.insert(Targets,#Targets + 1,{v.Parent,(Gun.Position - v.Position).Magnitude})
- else
- end
- end
- end
- end
- end
- table.sort(Targets, compare)
- if Targets[1] == nil then
- return nil,nil
- else
- return Targets[1][1],Targets[1][2]
- end
- end
- while true do
- wait()
- local Human,Distance = FindTarget()
- if Human then
- if Distance < dist then
- Light.BrickColor = BrickColor.new("Bright red")
- local Tween = tweenservice:Create(Gun,TweenInfo.new(0.1,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0,false, 0), {CFrame = CFrame.new(Gun.Position,Human.Head.Position)})
- Tween:Play()
- Tween:Destroy()
- -- Gun.CFrame = CFrame.new(Gun.Position,Human.Head.Position)
- wait(0.1)
- Fire(Human,Distance)
- Human.Humanoid:TakeDamage(10)
- else
- end
- else
- Light.BrickColor = BrickColor.new("Lime green")
- local Tween = tweenservice:Create(Gun,TweenInfo.new(0.1,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0,false, 0), {CFrame = CFrame.new(Gun.Position) * CFrame.Angles(0,0,0)})
- Tween:Play()
- Tween:Destroy()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement