Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sentry = script.Parent
- local base = sentry:WaitForChild("Base")
- local turret = sentry:WaitForChild("Turret")
- local shootPart = turret:WaitForChild("ShootPart")
- local shootSound = shootPart:WaitForChild("ShootSound")
- local isCooldown = false
- local timePerBullet = 0.1
- local bulletDistance = 1000
- local maxDistance = math.huge
- local maxAmmo = 500
- local currentAmmo = maxAmmo
- local plrs = game.Players
- while wait() do
- if isCooldown then return end
- local charAttacking
- for i, plr in pairs(plrs:GetPlayers()) do
- local char = plr.Character
- if char and char:FindFirstChild("Humanoid") then
- if not charAttacking then charAttacking = char end
- if (shootPart.Position - char.HumanoidRootPart.Position).Magnitude < (shootPart.Position - charAttacking.HumanoidRootPart.Position).Magnitude then charAttacking = char end
- end
- end
- if charAttacking and (shootPart.Position - charAttacking.HumanoidRootPart.Position).Magnitude <= maxDistance and charAttacking.Humanoid.Health > 0 then
- if currentAmmo > 0 then
- isCooldown = true
- currentAmmo = currentAmmo - 1
- shootSound:Play()
- local newCFrame = CFrame.new(turret.PrimaryPart.Position, charAttacking.HumanoidRootPart.CFrame.Position)
- turret:SetPrimaryPartCFrame(newCFrame)
- local ray = Ray.new(shootPart.Position, shootPart.CFrame.LookVector * bulletDistance)
- local part, position = workspace:FindPartOnRay(ray, sentry)
- if part and part.Parent:FindFirstChild("Humanoid") then
- part.Parent.Humanoid:TakeDamage(5)
- end
- local bullet = Instance.new("Part")
- bullet.CFrame = CFrame.new(shootPart.Position, shootPart.CFrame.LookVector.Unit * bulletDistance) * CFrame.new(0, 0, -(shootPart.Position - shootPart.CFrame.LookVector * bulletDistance).Magnitude / 2)
- bullet.Size = Vector3.new(0.05, 0.05, (shootPart.Position - shootPart.CFrame.LookVector * bulletDistance).Magnitude)
- bullet.CanCollide = false
- bullet.Anchored = true
- bullet.Color = Color3.fromRGB(239, 184, 56)
- bullet.Material = Enum.Material.Metal
- bullet.Parent = workspace
- game.Debris:AddItem(bullet, 0.05)
- wait(timePerBullet)
- isCooldown = false
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement