Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Libraries
- local player = game.Players.LocalPlayer
- local char = player.Character or player.CharacterAdded:wait()
- local mouse = player:GetMouse()
- local cam = workspace.CurrentCamera
- local rs = game:GetService('RunService').RenderStepped
- local uis = game:GetService('UserInputService')
- --Fundmental Modules
- local gs = require(game.ReplicatedStorage.Modules.Fundementals.GameSettings)
- local eai = require(game.ServerScriptService.Modules.Classes.Enemy.EmemyAi)
- --Events
- local events = game.ReplicatedStorage.Events
- local signal = events:WaitForChild("Signal")
- --Main
- signal.OnClientEvent:connect(function(ver,p1,p2,p3)
- local bdfl = {
- SetupTurrent = function()
- local clp = true
- local lastrot = {
- x=0,
- y=0,
- z=0,
- }
- --Cloning
- local t = game.ReplicatedStorage.Assets.Turrets.RTurret:Clone()
- t.Parent = cam
- --Input
- uis.InputBegan:connect(function(io,gpe)
- if io.KeyCode == Enum.KeyCode.R and clp == true then
- if t:isA("Model") then
- if t.PrimaryPart ~= nil then
- t:SetPrimaryPartCFrame(t:GetPrimaryPartFrame()*CFrame.Angles(0,math.rad(5),0))
- lastrot.y = t.PrimaryPart.Rotation.Y
- else
- warn("Set Primary Part to base...")
- end
- elseif t:isA("BasePart") then
- t.CFrame = t.CFrame*CFrame.Angles(0,math.rad(5),0)
- lastrot.y = t.Rotation.Y
- end
- end
- end)
- local function castRay(o,o2)
- local mag = (o.PrimaryPart.Position-o2.Positon).magnitude
- local beam = Instance.new("Part")
- beam.BrickColor = BrickColor.new('Black')
- beam.Material = 'Neon'
- beam.Transparency = 0
- beam.Anchored = true
- beam.CanCollide = true
- beam.Size=Vector3.new(0.3,0.3,mag)
- beam.CFrame=CFrame.new(o.PrimaryPart.Position,o2.Position)*CFrame.new(0,0,mag/2)
- beam.Parent = cam
- game:GetService("Debris"):AddItem(beam,4)
- end
- local function trackEnemies()
- local cooldown = 0
- local closestpart
- spawn(function()
- while wait() do
- wait(cooldown)
- if #gs.CurrentCourse.Enemies:GetChildren()~= 0 then
- cooldown = 0
- for n,e in pairs(gs.CurrentCourse.Enemies:GetChildren()) do
- if e~= nil then
- local mag = (o.PrimaryPart.Position-e.Position).magnitude
- if mag <= 4.5 then
- closestpart = e
- end
- end
- end
- if closestpart then
- castRay(o, closestpart)
- signal:FireServer('Backdoor','DestroyEnemy',closestpart)
- closestpart = nil
- cooldown = 3
- end
- end
- end
- end)
- end
- mouse.Button1Down:connect(function()
- clp = false
- trackEnemies(t)
- end)
- mouse.TargetFilter = t
- rs:connect(function()
- if clp == true then
- if mouse.Target ~= nil then
- if mouse.Target.Parent.Parent == gs.CurrentCourse then
- signal:FireServer("Backdoor","UpdateTurretPosition",t,
- CFrame.new(mouse.Target.Position.X((t.PrimaryPart.Size.Y/2)+mouse.Target.Position.Y)+0.5,mouse.Target.Position.Z)*CFrame.Angles(0,lastrot.y,0))
- end
- end
- end
- end)
- end
- }
- if ver == 'Backdoor' then
- bdfl[p1](p2,p3)
- elseif ver == "Frontdoor"then
- signal:FireServer("Backdoor", p1,p2,p3)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment