Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------Variable-----------------------------
- turretpos = Vector3.new(0, 120, 0)
- avoid = {"Dimitriye98"}
- --------------------------Building Script--------------------------
- local m = Instance.new("Message")
- m.Parent = game.Workspace
- for i=2,100,2 do
- m.Text = "Loading Turret Script: "..i.."%"
- for x=2,i,2 do
- m.Text = "|"..m.text.."|"
- end
- wait(0.1)
- end
- m.Text = "Initializing."
- for i=1,30 do
- if i%3 == 1 then
- m.Text = "Initializing."
- else
- m.Text = m.Text.."."
- end
- wait(0.5)
- end
- local waiting = true
- local launch = coroutine.create(function()
- local n = 1
- local m = m
- while waiting do
- if n%3 == 1 then
- m.Text = "Launching."
- else
- m.Text = m.Text.."."
- end
- n = n+1
- wait(0.5)
- end
- end)
- coroutine.resume(launch)
- wait(10)
- local model = Instance.new("Model")
- model.Name = "Turret"
- local engine = Instance.new("Part")
- engine.Name = "Engine"
- engine.CFrame = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- engine.formFactor = 0
- engine.Size = Vector3.new(1, 1, 4)
- engine.BrickColor = BrickColor.new(1)
- engine.TopSurface = 0
- engine.BottomSurface = 0
- engine.Locked = true
- engine.Parent = model
- local hole = Instance.new("Hole")
- hole.FaceId = 5
- hole.Parent = engine
- local enginemesh = Instance.new("SpecialMesh")
- enginemesh.MeshType = 3
- enginemesh.Scale = Vector3.new(2, 2, 1)
- enginemesh.Parent = engine
- local gyro = Instance.new("BodyGyro")
- gyro.maxTorque = Vector3.new(9000, 9000, 9000)
- gyro.Parent = engine
- local hover = Instance.new("BodyPosition")
- hover.position = turretpos
- hover.maxForce = Vector3.new(9000, 9000, 9000)
- hover.Parent = engine
- local indicator = Instance.new("Part")
- indicator.Name = "StatusIndicator"
- indicator.BrickColor = BrickColor.new(26)
- indicator.formFactor = 2
- indicator.Size = Vector3.new(1, 0.4, 1)
- indicator.Locked = true
- indicator.BottomSurface = 0
- indicator.TopSurface = 0
- indicator.CFrame = CFrame.new(0, 0.699999988, -0.5, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- indicator.Parent = model
- local W = Instance.new("Weld")
- W.Part0 = engine
- W.Part1 = indicator
- local CJ = CFrame.new(engine.Position)
- local C0 = engine.CFrame:inverse()*CJ
- local C1 = indicator.CFrame:inverse()*CJ
- W.C0 = C0
- W.C1 = C1
- W.Parent = engine
- local indicatormesh = Instance.new("SpecialMesh")
- indicatormesh.MeshType = 1
- indicatormesh.Scale = Vector3.new(1, 1.5, 1)
- indicatormesh.Parent = indicator
- engine.CFrame = CFrame.new(turretpos)
- model.archivable = false
- model.Parent = game.Workspace
- script.Parent = engine
- script.Name = "AimScript"
- --------------------------Control Script--------------------------
- function move(target)
- local dir = (target.Position - engine.Position).unit
- local spawnPos = engine.Position
- local pos = spawnPos + (dir * 1)
- engine:findFirstChild("BodyGyro").cframe = CFrame.new(pos, pos + dir)
- engine:findFirstChild("BodyGyro").maxTorque = Vector3.new(9000,9000,9000)
- end
- function fireLaser(target)
- local origin = script.Parent.Position+script.Parent.CFrame.lookVector*1.8
- local dist = (origin - target).magnitude
- local part = Instance.new("Part")
- part.Size = Vector3.new(1,dist,1)
- part.CFrame = CFrame.new((origin + target)/2, target) * CFrame.fromEulerAnglesXYZ(math.pi/2,0,0)
- part.BrickColor = BrickColor.new("Bright red")
- part.Transparency = 0.5
- part.TopSurface = 0
- part.BottomSurface = 0
- part.CanCollide = false
- part.Anchored = true
- local mesh = Instance.new("CylinderMesh")
- mesh.Scale = Vector3.new(0.5,1,0.5)
- mesh.Parent = part
- coroutine.resume(coroutine.create(function(laser)
- local trans = 1 - laser.Transparency
- for i=1,5 do
- laser.Transparency = laser.Transparency + trans/5
- wait(0.1)
- end
- laser:remove()
- end), part)
- part.Parent = game.Workspace
- local explosion = Instance.new("Explosion")
- explosion.Position = target
- explosion.Parent = game.Workspace
- end
- function checkName(name, table)
- for i=1,#table do
- if type(table[i]):lower() == "string" and table[i]:lower() == name:lower() then return true end
- end
- return false
- end
- function findNearestTorso(pos)
- list = game.Players:GetChildren()
- torso = nil
- human = nil
- for i=1, #list do
- if list[i].Character ~= nil and not checkName(list[i].Name, avoid) then
- local temp = list[i].Character:findFirstChild("Torso")
- human = list[i].Character:findFirstChild("Humanoid")
- if temp ~= nil and human ~= nil and human.Health > 0 and human.Parent:findFirstChild("ForceField") == nil then
- if torso == nil or (temp.Position - pos).magnitude < (torso.Position - pos).magnitude then
- torso = temp
- dist = (temp.Position - pos).magnitude
- end
- end
- end
- end
- return torso
- end
- waiting = false
- coroutine.yield(launch)
- m.Text = "Ready"
- game:getService("Debris"):addItem(m,3)
- while true do
- local torso = findNearestTorso(engine.Position)
- if torso ~= nil then
- indicator.BrickColor = BrickColor.new(37)
- move(torso)
- pos = torso.Position
- wait(math.random(0.7, 1.3))
- fireLaser(pos)
- indicator.BrickColor = BrickColor.new(21)
- wait(4.7)
- else indicator.BrickColor = BrickColor.new(26) end
- wait(0.3)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement