Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local turret = {}
- local debris = game:GetService("Debris")
- function turret.startTurret(part)
- local lastShot = tick()
- while true do
- local lastMag, object = 200, nil
- for i,v in pairs(workspace.Zombies:GetChildren()) do
- local magnitude = (v.HumanoidRootPart.Position - part.Position).magnitude
- if magnitude < lastMag then
- lastMag = magnitude
- object = v
- end
- end
- if lastMag < 50 then
- if object then
- part.Parent:SetPrimaryPartCFrame(CFrame.new(part.Position, Vector3.new(object.UpperTorso.Position.X, part.Position.Y, object.UpperTorso.Position.Z))); wait()
- end
- end
- if tick() - lastShot >= 1 then
- if object and object:FindFirstChild("Humanoid") then
- if object.Humanoid.Health > 0 then
- if lastMag < 50 then -- LAST MAG CAUSES ISSUES AND DELAYS SHOOTING. FIND OUT WHY
- local muzzle = part.Parent.Muzzle
- local ray = Ray.new(muzzle.CFrame.p, (Vector3.new(object.HumanoidRootPart.Position.X, muzzle.Position.Y, object.HumanoidRootPart.Position.Z) - muzzle.CFrame.p).unit * 300)
- local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {game.Players:GetPlayers()[1].Character, workspace.LevelGeometry}, false, true)
- if part:IsDescendantOf(workspace.Zombies) then
- part.Parent.Humanoid:TakeDamage(8)
- local beam = Instance.new("Part", workspace)
- beam.BrickColor = BrickColor.new("Deep orange")
- beam.FormFactor = "Custom"
- beam.Material = "Neon"
- beam.Transparency = 0.2
- beam.Anchored = true
- beam.Locked = true
- beam.CanCollide = false
- local distance = (muzzle.CFrame.p - position).magnitude
- beam.Size = Vector3.new(0.15, 0.15, distance)
- beam.CFrame = CFrame.new(muzzle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
- local soundcopy = game.SoundService.Turret:Clone()
- soundcopy.Parent = workspace
- soundcopy:Play()
- debris:AddItem(soundcopy, soundcopy.TimeLength)
- debris:AddItem(beam, 0.01)
- lastShot = tick()
- end
- end
- end
- end
- end
- wait()
- end
- end
- return turret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement