Advertisement
Nutgear

modifiable gun idk

Oct 12th, 2020 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.47 KB | None | 0 0
  1.  
  2. --https://github.com/Mokiros/roblox-FE-compatibility
  3. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  4. local Player,game,owner = owner,game
  5. local RealPlayer = Player
  6. do
  7.     print("FE Compatibility code V2 by Mokiros")
  8.     local RealPlayer = RealPlayer
  9.     script.Parent = RealPlayer.Character
  10.    
  11.     --Fake event to make stuff like Mouse.KeyDown work
  12.     local Disconnect_Function = function(this)
  13.         this[1].Functions[this[2]] = nil
  14.     end
  15.     local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
  16.     local FakeEvent_Metatable = {__index={
  17.         Connect = function(this,f)
  18.             local i = tostring(math.random(0,10000))
  19.             while this.Functions[i] do
  20.                 i = tostring(math.random(0,10000))
  21.             end
  22.             this.Functions[i] = f
  23.             return setmetatable({this,i},Disconnect_Metatable)
  24.         end
  25.     }}
  26.     FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
  27.     local function fakeEvent()
  28.         return setmetatable({Functions={}},FakeEvent_Metatable)
  29.     end
  30.    
  31.     --Creating fake input objects with fake variables
  32.     local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
  33.     FakeMouse.keyUp = FakeMouse.KeyUp
  34.     FakeMouse.keyDown = FakeMouse.KeyDown
  35.     local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  36.     local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  37.         CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  38.     end}
  39.     --Merged 2 functions into one by checking amount of arguments
  40.     CAS.UnbindAction = CAS.BindAction
  41.    
  42.     --This function will trigger the events that have been :Connect()'ed
  43.     local function TriggerEvent(self,ev,...)
  44.         for _,f in pairs(self[ev].Functions) do
  45.             f(...)
  46.         end
  47.     end
  48.     FakeMouse.TriggerEvent = TriggerEvent
  49.     UIS.TriggerEvent = TriggerEvent
  50.    
  51.     --Client communication
  52.     local Event = Instance.new("RemoteEvent")
  53.     Event.Name = "UserInput_Event"
  54.     Event.OnServerEvent:Connect(function(plr,io)
  55.         if plr~=RealPlayer then return end
  56.         FakeMouse.Target = io.Target
  57.         FakeMouse.Hit = io.Hit
  58.         if not io.isMouse then
  59.             local b = io.UserInputState == Enum.UserInputState.Begin
  60.             if io.UserInputType == Enum.UserInputType.MouseButton1 then
  61.                 return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
  62.             end
  63.             if io.UserInputType == Enum.UserInputType.MouseButton2 then
  64.                 return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
  65.             end
  66.             for _,t in pairs(CAS.Actions) do
  67.                 for _,k in pairs(t.Keys) do
  68.                     if k==io.KeyCode then
  69.                         t.Function(t.Name,io.UserInputState,io)
  70.                     end
  71.                 end
  72.             end
  73.             FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  74.             UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
  75.         end
  76.     end)
  77.     Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
  78.     local Mouse = owner:GetMouse()
  79.     local UIS = game:GetService("UserInputService")
  80.     local input = function(io,RobloxHandled)
  81.         if RobloxHandled then return end
  82.         --Since InputObject is a client-side instance, we create and pass table instead
  83.         Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
  84.     end
  85.     UIS.InputBegan:Connect(input)
  86.     UIS.InputEnded:Connect(input)
  87.     local h,t
  88.     --Give the server mouse data every second frame, but only if the values changed
  89.     --If player is not moving their mouse, client won't fire events
  90.     local HB = game:GetService("RunService").Heartbeat
  91.     while true do
  92.         if h~=Mouse.Hit or t~=Mouse.Target then
  93.             h,t=Mouse.Hit,Mouse.Target
  94.             Event:FireServer({isMouse=true,Target=t,Hit=h})
  95.         end
  96.         --Wait 2 frames
  97.         for i=1,2 do
  98.             HB:Wait()
  99.         end
  100.     end]==],script)
  101.    
  102.     ----Sandboxed game object that allows the usage of client-side methods and services
  103.     --Real game object
  104.     local RealGame = game
  105.    
  106.     --Metatable for fake service
  107.     local FakeService_Metatable = {
  108.         __index = function(self,k)
  109.             local s = rawget(self,"_RealService")
  110.             if s then
  111.                 return typeof(s[k])=="function"
  112.                     and function(_,...)return s[k](s,...)end or s[k]
  113.             end
  114.         end,
  115.         __newindex = function(self,k,v)
  116.             local s = rawget(self,"_RealService")
  117.             if s then s[k]=v end
  118.         end
  119.     }
  120.     local function FakeService(t,RealService)
  121.         t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService
  122.         return setmetatable(t,FakeService_Metatable)
  123.     end
  124.    
  125.     --Fake game object
  126.     local FakeGame = {
  127.         GetService = function(self,s)
  128.             return rawget(self,s) or RealGame:GetService(s)
  129.         end,
  130.         Players = FakeService({
  131.             LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
  132.         },"Players"),
  133.         UserInputService = FakeService(UIS,"UserInputService"),
  134.         ContextActionService = FakeService(CAS,"ContextActionService"),
  135.         RunService = FakeService({
  136.             _btrs = {},
  137.             RenderStepped = RealGame:GetService("RunService").Heartbeat,
  138.             BindToRenderStep = function(self,name,_,fun)
  139.                 self._btrs[name] = self.Heartbeat:Connect(fun)
  140.             end,
  141.             UnbindFromRenderStep = function(self,name)
  142.                 self._btrs[name]:Disconnect()
  143.             end,
  144.         },"RunService")
  145.     }
  146.     rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer)
  147.     FakeGame.service = FakeGame.GetService
  148.     FakeService(FakeGame,game)
  149.     --Changing owner to fake player object to support owner:GetMouse()
  150.     game,owner = FakeGame,FakeGame.Players.LocalPlayer
  151. end
  152.  
  153. --Past this line is the main code, above this line would be Voidacity Compatibility thing
  154.  
  155. local t = Instance.new("Tool",owner.Backpack)
  156. t.Name = "Whitworth Rifle"
  157. t.GripForward = Vector3.new(1, -0, 0)
  158. t.GripRight = Vector3.new(0, 0, 1)
  159. t.GripUp = Vector3.new(0, 1, -0)
  160. t.GripPos = Vector3.new(-1, -0.1, -0.1)
  161.  
  162.  
  163. local h = Instance.new("Part",t)
  164. h.Name = "Handle"
  165. h.BrickColor = BrickColor.Black()
  166.  
  167. local m = Instance.new("FileMesh",h)
  168. m.MeshId = "rbxassetid://583551291"
  169. m.TextureId = "rbxassetid://583551296"
  170. m.Scale = Vector3.new(0.01,0.01,0.01)
  171.  
  172. local fire = Instance.new("PointLight",h)
  173. fire.Color = Color3.fromRGB(255, 255, 0)
  174. fire.Enabled = false
  175.  
  176. h.CFrame = CFrame.new(219.5, 1.77000618, 75, 1, 1.13660383e-13, 0, 1.13660383e-13, 1, 0, 0, 0, 1)
  177. h.Position = Vector3.new(219.5, 1.77000618, 75)
  178.  
  179. local cam = workspace.CurrentCamera
  180.  
  181. local cooldown = 60/60 --Property 1
  182. local rate = 60/900 --Property 2
  183. local bursts = 5 --Property 3
  184. local damage = (29/7.62)*(9/1) --Property 4
  185. print(damage)
  186. local penetration = 9*2 --Property 5
  187. local range = 300*2.4 --Property 6
  188. local recoil = 45 --Propety 7, this is toolgrip recoil
  189. local suppressed = false --Property 8
  190. local fired = false
  191. fire.Brightness = recoil/10
  192.  
  193. local s
  194.  
  195. --ARMS
  196. --Sound variable
  197.  
  198. local fs = Instance.new("Sound",h)
  199. fs.SoundId = "rbxassetid://2739880827"
  200. fs.Volume = 10
  201. fs.MaxDistance = math.huge
  202.  
  203. local firepitch = 1
  204.  
  205. if suppressed == true then
  206.     firepitch = firepitch*2
  207.     fs.Volume = 1.25
  208.     range = range*0.8
  209. end
  210.  
  211. local mouse2 = owner:GetMouse()
  212.  
  213. local aiming = false
  214.  
  215. t.Activated:connect(function()
  216.     if fired == false then
  217.        
  218.        
  219.         fired = true
  220.         for i = 1,bursts do
  221.             fs.PlaybackSpeed = fs.PlaybackSpeed + (math.random(-6,6)/10)
  222.             NLS([==[
  223.         recoil = 45
  224.        
  225.        
  226.         recoil = recoil/5
  227.         workspace.CurrentCamera.CFrame=workspace.CurrentCamera.CFrame*CFrame.Angles(math.random(recoil*1,recoil*1.25)/360,math.random(recoil/1.5,recoil/1.5)/360,math.random(recoil*-1/1.5,recoil/1.5)/360)]==],script)
  228.             local m = owner:GetMouse()
  229.            
  230.  
  231.             fs:Play()
  232.            
  233.             local impact = Instance.new("Part")
  234.             impact.Size = Vector3.new(0.5,0.5,0.5)
  235.             impact.Shape = 0
  236.             impact.Transparency = 0.5
  237.             impact.Anchored = true
  238.             impact.Position = m.Hit.p
  239.             impact.CanCollide = false
  240.  
  241.            
  242.            
  243.             if m.Target ~= nil then --search workspace for le target
  244.                
  245.                 local Dis = h.Position.Magnitude  - m.Target.Position.Magnitude
  246.                 local Distance = Dis
  247.                
  248.                 if Distance <= 0 then
  249.                     Distance = Distance*(-1)
  250.                 end    
  251.                 print(Distance)
  252.                 if Distance <= range then
  253.                     --m.Target:BreakJoints()
  254.                     impact.Position = m.Target.Position
  255.                     impact.Parent = workspace
  256.                     if m.Target.Locked ~= true then
  257.                         m.Target.Transparency = m.Target.Transparency + (penetration-((penetration/2)/Distance))/750
  258.                     end
  259.                     if m.Target.parent ~= nil and m.Target.Parent:IsA("Accessory") then
  260.                         m.Target:BreakJoints()
  261.                         m.Target.CanCollide = true
  262.                         m.Target.Velocity = m.Target.CFrame.LookVector*(range*-0.1)
  263.                     end
  264.                     if m.Target.parent ~= nil and m.Target.Parent:IsA("Tool") then
  265.                         m.Target:BreakJoints()
  266.                         m.Target.Velocity = m.Target.CFrame.LookVector*(range*-0.1)
  267.                         m.Target.CanCollide = true
  268.                         m.Target.Parent.Parent = workspace
  269.                     end
  270.                     if m.Target.Transparency >= 1  then
  271.                         m.Target:Destroy()
  272.                     end
  273.  
  274.                     local t2
  275.                     if m.Target.Parent ~= nil then
  276.                     t2 = m.Target.Parent:FindFirstChild("Humanoid")
  277.                     end
  278.                    
  279.                     if t2~=nil then
  280.                          
  281. --                      is1 = Instance.new("Sound",m.Target)
  282. --                      is1.SoundId = "rbxassetid://255661850"
  283. --                      is1.Volume = 1
  284. --                      is1.PlayOnRemove = true
  285. --                      is1:Destroy()
  286.                         local distancedamage = damage-((damage/2)/Distance)
  287.                        
  288.                         if m.Target.Name == "Head" then
  289.                             distancedamage = distancedamage*5.6
  290.                             m.Target.Velocity = m.Target.CFrame.LookVector*(range*-0.01)
  291.                         end
  292.                         if m.Target.Name == "Torso" or m.Target.Name == "UpperTorso" then
  293.                             distancedamage = distancedamage*1.2
  294.                         end                                    
  295.                         t2.Health = t2.Health - distancedamage
  296.                         t2.BreakJointsOnDeath = false      
  297.                        
  298.                         m.Target.Transparency = m.Target.Transparency + distancedamage/3000
  299.                        
  300.                         local R = m.Target.BrickColor.Color.R+(distancedamage/(765/1))     
  301.                         local G = m.Target.BrickColor.Color.G-(distancedamage/(255/2)) 
  302.                         local B = m.Target.BrickColor.Color.B-(distancedamage/(255/2))         
  303.                        
  304.                         m.Target.BrickColor = BrickColor.new(R,G,B)
  305.                         t2.Sit = true
  306.                        
  307.                         if t2.Health <= t2.MaxHealth/4 then
  308.                             t2.Sit = false
  309.                             t2.PlatformStand = true
  310.                         end
  311.                     end
  312.                 end
  313.                
  314.             end
  315.             t.GripPos = Vector3.new(t.GripPos.X + recoil/300,t.GripPos.Y,t.GripPos.Z )
  316.             fire.Enabled = true
  317.             wait(rate/2)
  318.             t.GripPos = Vector3.new(t.GripPos.X - recoil/300,t.GripPos.Y,t.GripPos.Z)
  319.             fire.Enabled = false
  320.             impact:Destroy()
  321.             wait(rate/2)
  322.         end
  323.         fs.PlaybackSpeed = firepitch
  324.         wait(cooldown)
  325.        
  326.         fired = false
  327.        
  328.     end
  329. end)
  330.  
  331.  
  332. mouse2.KeyUp:connect(function(k)
  333.     local key = k:lower()
  334.     if key == "q" then
  335.         if aiming == false then
  336.             aiming = true
  337.             NLS([==[workspace.CurrentCamera.FieldOfView = 70/3]==],script)
  338.             for i = 1,10 do
  339.             wait()
  340.                 t.GripPos = Vector3.new((-1/10)*i, (-0.38/10)*i, (1.37/10)*i) --0, -0.4, 1.3
  341.             end
  342.             mouse2.Icon = 'http://www.roblox.com/asset/?id=5225039196'
  343.             t.GripPos = Vector3.new(-1, -0.38, 1.37)
  344.         else
  345.             aiming = false
  346.             NLS([==[workspace.CurrentCamera.FieldOfView = 70]==],script)
  347.             for i = 1,10 do
  348.                 wait()
  349.                 t.GripPos = Vector3.new((-1/i), (-0.38/i), (-1.37/i))
  350.             end
  351.             t.GripPos = Vector3.new(-1, -0.1, -0.1)
  352.             mouse2.Icon = 'http://www.roblox.com/asset/?id=120149138'
  353.         end
  354.     end
  355. end)
  356. --http://www.roblox.com/asset/?id=5225039196
  357. t.Equipped:connect(function()
  358.     mouse2.Icon = 'http://www.roblox.com/asset/?id=120149138'
  359.     game.Players.LocalPlayer.CameraMode = "LockFirstPerson"
  360. end)
  361. t.Unequipped:connect(function()
  362.     mouse2.Icon = ''
  363.     game.Players.LocalPlayer.CameraMode = "Classic"
  364. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement