capthehacker99

Roblox Turret Script

Dec 7th, 2021
3,906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. local bullet = script.Bullet
  2. bullet.Parent = nil
  3. local tab = {}
  4. script.Parent.Trigger.Touched:Connect(function(prt)
  5.     if prt.Parent and prt.Parent:FindFirstChildOfClass("Humanoid") and prt.Parent:FindFirstChild("HumanoidRootPart") and not tab[prt.Parent] then
  6.         coroutine.resume(coroutine.create(function()
  7.             tab[prt.Parent] = true;
  8.             while true do
  9.                 wait(0.5)
  10.                 if prt.Parent:FindFirstChild("HumanoidRootPart") and prt.Parent:FindFirstChildOfClass("Humanoid") and prt.Parent:FindFirstChildOfClass("Humanoid").Health > 0 then
  11.                     if (prt.Parent:FindFirstChild("HumanoidRootPart").Position-script.Parent.Main.Position).magnitude > 35 then
  12.                         break;
  13.                     end
  14.                     script.Parent.Main.CFrame = CFrame.new(script.Parent.Main.Position,prt.Parent:FindFirstChild("HumanoidRootPart").Position)
  15.                     local newbullet = bullet:Clone()
  16.                     newbullet.CFrame = script.Parent.Barrel.ShotPoint.WorldCFrame;
  17.                     Instance.new("BodyVelocity",newbullet).Velocity = script.Parent.Main.CFrame.LookVector*200;
  18.                     newbullet.Touched:connect(function(prta)
  19.                         if prta.Parent and prta.Parent:FindFirstChildOfClass("Humanoid") then
  20.                             prta.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(25);
  21.                             newbullet:Destroy();
  22.                            
  23.                         end
  24.                     end)
  25.                     game:GetService("Debris"):AddItem(newbullet,20);
  26.                     newbullet.Parent = workspace
  27.                 else
  28.                     break;
  29.                 end
  30.             end
  31.             tab[prt.Parent] = false
  32.         end))
  33.     end
  34. end)
Advertisement
Add Comment
Please, Sign In to add comment