Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wait(5)
- local FastCast = require(game.ReplicatedStorage.FastCastRedux)
- local PartCache = require(game.ReplicatedStorage.PartCache)
- local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
- bulletsFolder.Name = "BulletFolder"
- local bulletTemplate = game.ReplicatedStorage.CosmeticBullet
- local caster = FastCast.new()
- local castParams = RaycastParams.new()
- castParams.FilterType = Enum.RaycastFilterType.Blacklist
- castParams.FilterDescendantsInstances = {script.Parent}
- castParams.IgnoreWater = true
- local bulletCache = PartCache.new(bulletTemplate, 100, bulletsFolder)
- local castBehavior = FastCast.newBehavior()
- castBehavior.RaycastParams = castParams
- castBehavior.Acceleration = Vector3.new(0, 0, 0)
- castBehavior.AutoIgnoreContainer = false
- castBehavior.CosmeticBulletContainer = bulletsFolder
- castBehavior.CosmeticBulletProvider = bulletCache
- local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
- if bullet then
- local bulletLength = bullet.Size.Z/2
- local offset = CFrame.new(0, 0, -(length - bulletLength))
- bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
- end
- end
- local function onRayHit(cast, result, velocity, bullet)
- local hit = result.Instance
- local character = hit:FindFirstAncestorWhichIsA("Model")
- if character and character:FindFirstChild("Humanoid") then
- character.Humanoid:TakeDamage(50)
- end
- delay(2, function()
- bulletCache:ReturnPart(bullet)
- end)
- end
- local turretJoint = script.Parent.Main.Upper.TurretJoint
- local mainJoint = script.Parent.Main.Joint
- local cooldown = false
- local damage = 10
- local fireRate = 0.02
- local distance = 200
- local function GetClosestCharacter (fromPosition, range)
- local bestMagnitude = 1000000
- local closestChar = nil
- for i, v in ipairs(game.Players:GetChildren()) do
- local char = v.Character
- local head = char.Head
- local distance = (fromPosition - head.Position).Magnitude
- if distance < bestMagnitude and distance < range and char.Humanoid.Health > 0 then
- bestMagnitude = distance
- closestChar = char
- end
- end
- return closestChar
- end
- while wait(fireRate) do
- local target = nil
- if script.Parent.Active.Value == true then
- local char = GetClosestCharacter(turretJoint.Position, distance)
- if char then
- turretJoint.CFrame = turretJoint.CFrame:Lerp(CFrame.new(turretJoint.Position, char.HumanoidRootPart.Position), 0.5)
- mainJoint.Orientation = Vector3.new(0,turretJoint.Orientation.Y,0)
- if cooldown == false then
- local origin = script.Parent.Main.Upper.FirePoint.Position
- local direction = (char.HumanoidRootPart.Position - origin).Unit
- cooldown = true
- caster:Fire(origin, direction, 1000, castBehavior)
- delay(2, function()
- cooldown = false
- end)
- end
- end
- end
- end
- caster.LengthChanged:Connect(onLengthChanged)
- caster.RayHit:Connect(onRayHit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement