Advertisement
Guest User

FrontEnd Script LUA

a guest
Dec 28th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 3.74 KB | None | 0 0
  1. local tool = script.Parent.Parent
  2. local player = game:GetService("Players").LocalPlayer
  3. local mouse = player:GetMouse()
  4. local hole = tool:WaitForChild("hole")
  5. local handle = tool:WaitForChild("handle")
  6. local actioService = game:GetService("ContextActionService")
  7. local mouseDown = false
  8. local equipped = false
  9.  
  10. --Folder--
  11. local animations = tool:WaitForChild("Animations")
  12. local configs = tool:WaitForChild("Configs")
  13. local remotes = tool:WaitForChild("Remotes")
  14.  
  15. --Animations--
  16. local recoilAnim = animations:WaitForChild("Recoil")
  17. local reloadAnim = animations:WaitForChild("Reload")
  18. local holdAnim = animations:WaitForChild("Hold")
  19.  
  20. --Animations Tracks--
  21. local recoilTrack
  22. local ReloadTrack
  23. local holdTrack
  24.  
  25. --configs--
  26. local allowTracing = configs:WaitForChild("AllowTracing")
  27. local range = configs:WaitForChild("Range")
  28.  
  29. --remotes--
  30. local canShoot = remotes:WaitForChild("CanShoot")
  31. local canReload = remotes:WaitForChild("CanReload")
  32. local hitRemote = remotes:WaitForChild("Hit")
  33. local reloadRemote = remotes:WaitForChild("Reload")
  34. local shootRemote = remotes:WaitForChild("Shoot")
  35.  
  36. --Assets--
  37. local flashGui = hole:WaitForChild("FlashGui")
  38.  
  39. --functions--
  40. local function equip()
  41.     equipped = true
  42.    
  43.     --Get Humanoid
  44.     local character = player.Character or player.CharacterAdded:wait()
  45.     local humanoid = character:WaitForChild("Humanoid")
  46.    
  47.     if humanoid then
  48.         --load animation--
  49.         pcall(function()
  50.             --hold Animation--
  51.             holdTrack = humanoid:LoadAnimation(holdAnim)
  52.             holdTrack:Play()
  53.         end)
  54.        
  55.         --reload animation--
  56.         pcall(function()
  57.             --hold Animation--
  58.             reloadTrack = humanoid:LoadAnimation(reloadAnim)
  59.         end)
  60.        
  61.         --Recoil animation--
  62.         pcall(function()
  63.             --hold Animation--
  64.             recoilTrack = humanoid:LoadAnimation(recoilAnim)
  65.         end)       
  66.        
  67.     end
  68. end
  69.  
  70. local function unequip()
  71.     equipped = false
  72.    
  73.     --stop animation--
  74.     if holdTrack  then
  75.         holdTrack:Stop()
  76.     end
  77.    
  78.         if ReloadTrack then
  79.             reloadTrack:stop()
  80.         end
  81.        
  82.         if recoilTrack then
  83.             recoilTrack:stop()
  84.     end
  85. end
  86.  
  87. local function reload()
  88.     if canReload:InvokeServer() then
  89.         --reload--
  90.         reloadRemote:FireServer()
  91.        
  92.         if reloadTrack then
  93.             reloadTrack:Play()
  94.     end
  95. end
  96.  
  97. local function fire()
  98.     --checks--
  99.     if canShoot:InvokeServer() then
  100.     end
  101.     --Initialize--
  102.     if recoilTrack then
  103.         recoilTrack:play()
  104.     end
  105.     flashGui.enebled = true
  106.    
  107.       --cast ray--
  108.      local ray = Ray.new(hole.Cframe.p, (mouse.hit.p - hole.Cframe.p).unit * range.value)
  109.      local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true )
  110.    
  111.         --hit detection--
  112.          if touch then
  113.             hitRemote:FireServer(touch)
  114.         end
  115.         shootRemote:FireServer()
  116.    
  117.     --trace--
  118.        if allowTracing.Value then
  119.         --create--
  120.         local trace = Instance.new("Part")
  121.         trace.Anchored = trace
  122.         trace.CanCollide = false
  123.         trace.Transparency = 0.5
  124.         trace.BrickColor = BrickColor.new("Black")
  125.         trace.Material = Enum.Material.SmoothPlastic
  126.        
  127.             --calculate
  128.         local distance = (hole.CFrame.p - position).magnitude
  129.            trace.Size = Vector3.new(0, 0, distance)
  130.             trace.CFrame = CFrame.new(hole.CFrame.p, position)* CFrame.new(0,0, -distance/2)
  131.             trace.parent = workspace
  132.            
  133.             --clean-up--
  134.             game:GetService("Debris"):AddItem(trace, 0,1)
  135.    
  136.             wait(0.1)
  137.    
  138.             flashGui.enebled = false
  139.         end
  140.     end
  141. end
  142.    
  143. --Event listeners--
  144. tool.Equipped:Connect(function()
  145.     equip()
  146.    
  147.     --Automatic Fire--
  148.     mouse.Button1Up:Connect(function()
  149.         mouseDown = false
  150.     end)
  151.     tool.Activated:Conntect (function()
  152.         mouseDown = true
  153.         repeat
  154.             wait(0.01)
  155.             fire()
  156.         until not mouseDown
  157.     end)
  158. end)
  159. tool.Unequipped:Connect(unequip)
  160. actioService:BindAction("Reload", reload, false, Enum.KeyCode,R)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement