Advertisement
Kaemi

Sniper Rifle

May 2nd, 2018
4,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.67 KB | None | 0 0
  1. -- This script has been converted to FE by iPxter
  2.  
  3.  
  4. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  5. local Player,Mouse,mouse,UserInputService,ContextActionService = owner
  6. do
  7. print("FE Compatibility code by Mokiros | Translated to FE by iPxter")
  8. script.Parent = Player.Character
  9.  
  10. --RemoteEvent for communicating
  11. local Event = Instance.new("RemoteEvent")
  12. Event.Name = "UserInput_Event"
  13.  
  14. --Fake event to make stuff like Mouse.KeyDown work
  15. local function fakeEvent()
  16. local t = {_fakeEvent=true,Connect=function(self,f)self.Function=f end}
  17. t.connect = t.Connect
  18. return t
  19. end
  20.  
  21. --Creating fake input objects with fake variables
  22. local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
  23. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  24. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  25. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  26. end}
  27. --Merged 2 functions into one by checking amount of arguments
  28. CAS.UnbindAction = CAS.BindAction
  29.  
  30. --This function will trigger the events that have been :Connect()'ed
  31. local function te(self,ev,...)
  32. local t = m[ev]
  33. if t and t._fakeEvent and t.Function then
  34. t.Function(...)
  35. end
  36. end
  37. m.TrigEvent = te
  38. UIS.TrigEvent = te
  39.  
  40. Event.OnServerEvent:Connect(function(plr,io)
  41. if plr~=Player then return end
  42. if io.isMouse then
  43. m.Target = io.Target
  44. m.Hit = io.Hit
  45. else
  46. local b = io.UserInputState == Enum.UserInputState.Begin
  47. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  48. return m:TrigEvent(b and "Button1Down" or "Button1Up")
  49. end
  50. for _,t in pairs(CAS.Actions) do
  51. for _,k in pairs(t.Keys) do
  52. if k==io.KeyCode then
  53. t.Function(t.Name,io.UserInputState,io)
  54. end
  55. end
  56. end
  57. m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  58. UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
  59. end
  60. end)
  61. Event.Parent = NLS([==[
  62. local Player = game:GetService("Players").LocalPlayer
  63. local Event = script:WaitForChild("UserInput_Event")
  64.  
  65. local UIS = game:GetService("UserInputService")
  66. local input = function(io,a)
  67. if a then return end
  68. --Since InputObject is a client-side instance, we create and pass table instead
  69. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState})
  70. end
  71. UIS.InputBegan:Connect(input)
  72. UIS.InputEnded:Connect(input)
  73.  
  74. local mouse = Player:GetMouse()
  75. local h,t
  76. --Give the server mouse data 30 times every second, but only if the values changed
  77. --If player is not moving their mouse, client won't fire events
  78. while wait(1/30) do
  79. if h~=Mouse.Hit or t~=Mouse.Target then
  80. h,t=Mouse.Hit,Mouse.Target
  81. Event:FireServer({isMouse=true,Target=t,Hit=h})
  82. end
  83. end]==],Player.Character)
  84. Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
  85. end
  86.  
  87. --Converted with ttyyuu12345's model to script plugin v4
  88. function sandbox(var,func)
  89. local env = getfenv(func)
  90. local newenv = setmetatable({},{
  91. __index = function(self,k)
  92. if k=="script" then
  93. return var
  94. else
  95. return env[k]
  96. end
  97. end,
  98. })
  99. setfenv(func,newenv)
  100. return func
  101. end
  102. cors = {}
  103. mas = Instance.new("Model",game:GetService("Lighting"))
  104. Tool0 = Instance.new("Tool")
  105. Part1 = Instance.new("Part")
  106. SpecialMesh2 = Instance.new("SpecialMesh")
  107. Sound3 = Instance.new("Sound")
  108. Sound4 = Instance.new("Sound")
  109. IntValue5 = Instance.new("IntValue")
  110. LocalScript6 = Instance.new("LocalScript")
  111. Animation7 = Instance.new("Animation")
  112. Animation8 = Instance.new("Animation")
  113. Animation9 = Instance.new("Animation")
  114. ScreenGui10 = Instance.new("ScreenGui")
  115. ImageLabel11 = Instance.new("ImageLabel")
  116. Frame12 = Instance.new("Frame")
  117. Frame13 = Instance.new("Frame")
  118. Frame14 = Instance.new("Frame")
  119. Frame15 = Instance.new("Frame")
  120. Frame16 = Instance.new("Frame")
  121. Frame17 = Instance.new("Frame")
  122. Frame18 = Instance.new("Frame")
  123. Sound19 = Instance.new("Sound")
  124. Sound20 = Instance.new("Sound")
  125. BoolValue21 = Instance.new("BoolValue")
  126. Tool0.Name = "Sniper"
  127. Tool0.Parent = mas
  128. Tool0.TextureId = "http://www.roblox.com/asset/?id=72013006"
  129. Tool0.GripForward = Vector3.new(-0.433848739, 0.867697477, 0.242644712)
  130. Tool0.GripPos = Vector3.new(0.125, -1, -0.5)
  131. Tool0.GripRight = Vector3.new(0.89442718, 0.44721359, 0)
  132. Tool0.GripUp = Vector3.new(0.108513996, -0.217027992, 0.970115185)
  133. Tool0.ToolTip = "Sniper: Press E to use scope."
  134. Part1.Name = "Handle"
  135. Part1.Parent = Tool0
  136. Part1.BrickColor = BrickColor.new("Pastel yellow")
  137. Part1.FormFactor = Enum.FormFactor.Symmetric
  138. Part1.Size = Vector3.new(1, 4, 1)
  139. Part1.CFrame = CFrame.new(-9.45001221, 2, 3.62001061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  140. Part1.Color = Color3.new(1, 1, 0.8)
  141. Part1.Position = Vector3.new(-9.45001221, 2, 3.62001061)
  142. Part1.Color = Color3.new(1, 1, 0.8)
  143. SpecialMesh2.Parent = Part1
  144. SpecialMesh2.MeshId = "http://www.roblox.com/asset/?id=72012972"
  145. SpecialMesh2.Scale = Vector3.new(1.5, 1.5, 1.5)
  146. SpecialMesh2.TextureId = "http://www.roblox.com/asset/?id=72012935"
  147. SpecialMesh2.VertexColor = Vector3.new(2, 2, 2)
  148. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  149. SpecialMesh2.Scale = Vector3.new(1.5, 1.5, 1.5)
  150. Sound3.Name = "Fire"
  151. Sound3.Parent = Part1
  152. Sound3.SoundId = "rbxassetid://10209875"
  153. Sound3.Volume = 1
  154. Sound4.Name = "Reload"
  155. Sound4.Parent = Part1
  156. Sound4.SoundId = "rbxassetid://2761842"
  157. Sound4.Volume = 1
  158. IntValue5.Name = "Ammo"
  159. IntValue5.Parent = Tool0
  160. LocalScript6.Parent = Tool0
  161. table.insert(cors,sandbox(LocalScript6,function()
  162. --Made by Stickmasterluke
  163.  
  164.  
  165. sp=script.Parent
  166.  
  167.  
  168. firerate=1.5
  169. range=950
  170. power=300
  171. rate=1/30
  172. spinuptime=0
  173. barreloffset=Vector3.new(0,2.75,.375)
  174. windvec=Vector3.new(2,-1,1).unit
  175. firetime=0
  176. maxammo=5
  177. reloadtime = 5
  178. ammo=maxammo
  179.  
  180. debris=game:GetService("Debris")
  181. equipped=false
  182. check=true
  183. firing=false
  184. reloading=false
  185.  
  186. function wait(TimeToWait)
  187. if TimeToWait ~= nil then
  188. local TotalTime = 0
  189. TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
  190. while TotalTime < TimeToWait do
  191. TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
  192. end
  193. else
  194. game:GetService("RunService").Heartbeat:wait()
  195. end
  196. end
  197.  
  198. function waitfor(parent,name)
  199. while parent:FindFirstChild(name)==nil do
  200. wait()
  201. end
  202. return parent:FindFirstChild(name)
  203. end
  204.  
  205. function checkintangible(hit)
  206. if hit and hit~=nil then
  207. if hit:IsDescendantOf(sp.Parent) or hit.Transparency>.8 or hit.Name=="Handle" or hit.Name=="Effect" or hit.Name=="Bullet" or hit.Name=="Laser" or string.lower(hit.Name)=="water" or hit.Name=="Rail" or hit.Name=="Arrow" then
  208. return true
  209. end
  210. end
  211. return false
  212. end
  213.  
  214. function castray(startpos,vec,length,ignore,delayifhit)
  215. local hit,endpos2=game.Workspace:FindPartOnRay(Ray.new(startpos,vec*length),ignore)
  216. if hit~=nil then
  217. if checkintangible(hit) then
  218. if delayifhit then
  219. wait()
  220. end
  221. hit,endpos2=castray(endpos2+(vec*.01),vec,length-((startpos-endpos2).magnitude),ignore,delayifhit)
  222. end
  223. end
  224. return hit,endpos2
  225. end
  226.  
  227. function wait(TimeToWait)
  228. if TimeToWait ~= nil then
  229. local TotalTime = 0
  230. TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
  231. while TotalTime < TimeToWait do
  232. TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
  233. end
  234. else
  235. game:GetService("RunService").Heartbeat:wait()
  236. end
  237. end
  238.  
  239. function drawbeam(beamstart,beamend,clr,fadedelay)
  240. local dist=(beamstart-beamend).magnitude
  241. local laser=Instance.new("Part")
  242. laser.Name="Effect"
  243. laser.Anchored=true
  244. laser.CanCollide=false
  245. laser.Shape="Block"
  246. laser.formFactor="Custom"
  247. laser.Size=Vector3.new(.2,.2,.2)
  248. laser.Transparency=0
  249. laser.Material=Enum.Material.Plastic
  250. laser.Locked=true
  251. laser.TopSurface=0
  252. laser.BottomSurface=0
  253. laser.BrickColor=clr
  254. laser.CFrame=CFrame.new(beamend,beamstart)*CFrame.new(0,0,-dist/2)*CFrame.Angles(math.pi/2,0,0)
  255. local m=Instance.new("SpecialMesh")
  256. m.Scale=Vector3.new(1,dist*5,1)
  257. m.MeshType="Brick"
  258. m.Parent=laser
  259. debris:AddItem(laser,fadedelay*0.5)
  260. laser.Parent=game.Workspace
  261.  
  262. --[[local frames=math.floor(fadedelay/rate)
  263. for frame=1,frames do
  264. wait(rate)
  265. local percent=frame/frames
  266. laser.CFrame=laser.CFrame+windvec*rate
  267. laser.Transparency=.5+(percent*.5)
  268. end]]
  269. wait(.5)
  270. laser:remove()
  271. end
  272.  
  273. function fire()
  274. local hu=sp.Parent:FindFirstChild("Humanoid")
  275. local he=sp.Parent:FindFirstChild("Head")
  276. local t=sp.Parent:FindFirstChild("Torso")
  277. if hu and hu.Health>0 and t and he and themouse~=nil and equipped then
  278.  
  279. anim2 = sp.Parent.Humanoid:LoadAnimation(sp.FireAni)
  280. if anim2 then anim2:Play() anim2:AdjustSpeed(1.75) end
  281. local startpos=he.Position
  282. local fakestartpos=(sp.Handle.CFrame*CFrame.new(barreloffset)).p
  283. local vec=(themouse.Hit.p-startpos).unit + (Vector3.new(math.random(-1000,1000),math.random(-1000,1000),math.random(-1000,1000)) / (1500*1500))
  284.  
  285. local p=Instance.new("Part")
  286. p.Name="Effect"
  287. p.BrickColor=BrickColor.new("Black")
  288. p.CanCollide=false
  289. p.TopSurface="Smooth"
  290. p.BottomSurface="Smooth"
  291. p.formFactor="Custom"
  292. p.Size=Vector3.new(0,0,0)
  293. p.Transparency=1
  294. local m=Instance.new("SpecialMesh")
  295. m.Parent=p
  296.  
  297. local hit,endpos=castray(startpos,vec,range,sp.Parent,false)
  298. local fakevec=(endpos-fakestartpos).unit
  299. if hit~=nil then
  300. local newcf=CFrame.new(endpos,endpos+fakevec)*CFrame.Angles(math.pi/2,0,0)*CFrame.new(0,0,0)
  301. p.CFrame=newcf
  302. local w=Instance.new("Weld")
  303. w.Part0=hit
  304. w.Part1=p
  305. w.C0=hit.CFrame:inverse()*newcf
  306. w.C1=newcf:inverse()*newcf
  307. w.Parent=p
  308.  
  309. local c=Instance.new("ObjectValue")
  310. c.Name="creator"
  311. c.Value=owner
  312. c.Parent=p
  313.  
  314. local Humanoid = hit.Parent:FindFirstChild("Humanoid")
  315. local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
  316. if Humanoid ~= nil then hit.Parent.Humanoid:TakeDamage(250)
  317. if Humanoid and Humanoid.Health <= 200 and hit.Name == "Head" and Player then sp["HeadshotPlayer"..math.random(1,2)]:Play() end
  318. else
  319. p.CFrame=CFrame.new(endpos,endpos+fakevec)
  320. p.Velocity=fakevec*power
  321. p.Parent=game.Workspace
  322. end
  323.  
  324.  
  325. debris:AddItem(p,1)
  326. p.Parent=game.Workspace
  327.  
  328. delay(0,function()
  329. drawbeam(fakestartpos,endpos,BrickColor.new("Bright yellow"),.1)
  330. end)
  331.  
  332. local sound=sp.Handle:FindFirstChild("Fire")
  333. if sound~=nil then
  334. --sound:Stop()
  335. sound:Play()
  336. end
  337.  
  338. local shoulder=t:FindFirstChild("Right Shoulder")
  339. if shoulder~=nil then
  340. shoulder.CurrentAngle=(math.pi/2)+.1
  341. end
  342. end
  343. end
  344. end
  345.  
  346. function onEquipped(mouse)
  347. equipped=true
  348. if mouse~=nil then
  349. anim = sp.Parent.Humanoid:LoadAnimation(sp.idle)
  350. if anim then anim:Play() end
  351. themouse=mouse
  352. mouse.Icon="http://www.roblox.com/asset/?id=2966012"
  353. mouse.Button1Down:connect(function()
  354. if sp.Enabled == false then return end
  355. sp.Enabled = false
  356. if ammo > 0 then
  357. ammo = ammo - 1
  358. fire()
  359. else
  360. Reload()
  361. end
  362. --mouse.Icon="http://www.roblox.com/asset/?id=2966012"
  363. Delay(firerate,function() if ammo == 0 then Reload() end sp.Enabled = true end)
  364. end)
  365. mouse.Button1Up:connect(function()
  366. --mouse.Icon="http://www.roblox.com/asset/?id=2966012"
  367. end)
  368. mouse.KeyDown:connect(function(Key)
  369. if string.lower(Key) == "r" then
  370. if ammo ~= maxammo and sp.Enabled == true then sp.Enabled = false Reload() sp.Enabled = true end
  371. elseif string.lower(Key) == "e" then
  372. if sp.AimDown.Value == false then
  373. Workspace.CurrentCamera.FieldOfView = 12.5
  374. local GUI = owner.PlayerGui:FindFirstChild("ZoomGui") or sp.ZoomGui:Clone()
  375. GUI.Parent = owner.PlayerGui
  376. owner.CameraMode = Enum.CameraMode.LockFirstPerson
  377. sp.AimDown.Value = true
  378. mouse.Icon="http://www.roblox.com/asset?id=187746799"
  379. else
  380. Workspace.CurrentCamera.FieldOfView = 70
  381. local GUI = owner.PlayerGui:FindFirstChild("ZoomGui")
  382. if GUI then GUI:Destroy() end
  383. owner.CameraMode = Enum.CameraMode.Classic
  384. sp.AimDown.Value = false
  385. mouse.Icon="http://www.roblox.com/asset/?id=2966012"
  386. end
  387. end
  388. end)
  389. end
  390. end
  391.  
  392. function Reload()
  393. anim3 = sp.Parent.Humanoid:LoadAnimation(sp.Reload)
  394. if anim3 then anim3:Play() anim3:AdjustSpeed(2.5) end
  395. local sound=sp.Handle:FindFirstChild("Reload")
  396. if sound~=nil then
  397. sound:Play()
  398. end
  399. wait(reloadtime)
  400. ammo = maxammo
  401. end
  402.  
  403. function onUnequipped()
  404. if anim then anim:Stop() end
  405. equipped=false
  406. themouse=nil
  407. if sp.AimDown.Value == true then
  408. Workspace.CurrentCamera.FieldOfView = 70
  409. local GUI = owner.PlayerGui:FindFirstChild("ZoomGui")
  410. if GUI then GUI:Destroy() end
  411. owner.CameraMode = Enum.CameraMode.Classic
  412. sp.AimDown.Value = false
  413. end
  414. end
  415.  
  416. sp.Equipped:connect(onEquipped)
  417. sp.Unequipped:connect(onUnequipped)
  418.  
  419. end))
  420. Animation7.Name = "FireAni"
  421. Animation7.Parent = Tool0
  422. Animation7.AnimationId = "http://www.roblox.com/Asset?ID=94332152"
  423. Animation8.Name = "Reload"
  424. Animation8.Parent = Tool0
  425. Animation8.AnimationId = "http://www.roblox.com/Asset?ID=94332664"
  426. Animation9.Name = "idle"
  427. Animation9.Parent = Tool0
  428. Animation9.AnimationId = "http://www.roblox.com/Asset?ID=94331086"
  429. ScreenGui10.Name = "ZoomGui"
  430. ScreenGui10.Parent = Tool0
  431. ImageLabel11.Name = "Scope"
  432. ImageLabel11.Parent = ScreenGui10
  433. ImageLabel11.Transparency = 1
  434. ImageLabel11.Size = UDim2.new(0, 750, 0, 750)
  435. ImageLabel11.Position = UDim2.new(0.5, -375, 0.5, -390)
  436. ImageLabel11.BackgroundColor3 = Color3.new(0, 0, 0)
  437. ImageLabel11.BackgroundTransparency = 1
  438. ImageLabel11.BorderColor3 = Color3.new(0, 0, 0)
  439. ImageLabel11.Image = "http://www.roblox.com/asset/?id=72002022"
  440. ImageLabel11.ImageColor3 = Color3.new(255, 255, 255)
  441. Frame12.Parent = ImageLabel11
  442. Frame12.Size = UDim2.new(0, 750, 0, 500)
  443. Frame12.Position = UDim2.new(0, 0, 0, -450)
  444. Frame12.BackgroundColor3 = Color3.new(0, 0, 0)
  445. Frame12.BorderColor3 = Color3.new(0, 0, 0)
  446. Frame13.Parent = ImageLabel11
  447. Frame13.Size = UDim2.new(0, 750, 0, 500)
  448. Frame13.Position = UDim2.new(0, 0, 1, -50)
  449. Frame13.BackgroundColor3 = Color3.new(0, 0, 0)
  450. Frame13.BorderColor3 = Color3.new(0, 0, 0)
  451. Frame14.Parent = ImageLabel11
  452. Frame14.Size = UDim2.new(0, 500, 1, 100)
  453. Frame14.Position = UDim2.new(1, -50, 0, -50)
  454. Frame14.BackgroundColor3 = Color3.new(0, 0, 0)
  455. Frame14.BorderColor3 = Color3.new(0, 0, 0)
  456. Frame15.Parent = ImageLabel11
  457. Frame15.Size = UDim2.new(0, 500, 1, 100)
  458. Frame15.Position = UDim2.new(0, -450, 0, -50)
  459. Frame15.BackgroundColor3 = Color3.new(0, 0, 0)
  460. Frame15.BorderColor3 = Color3.new(0, 0, 0)
  461. Frame16.Name = "Crosshair"
  462. Frame16.Parent = ScreenGui10
  463. Frame16.Size = UDim2.new(1, 0, 0, 2)
  464. Frame16.Position = UDim2.new(0, 0, 0.5, -16)
  465. Frame16.BackgroundColor3 = Color3.new(0, 0, 0)
  466. Frame16.BorderColor3 = Color3.new(0, 0, 0)
  467. Frame16.BorderSizePixel = 0
  468. Frame17.Name = "Crosshair"
  469. Frame17.Parent = ScreenGui10
  470. Frame17.Size = UDim2.new(0, 2, 1, 0)
  471. Frame17.Position = UDim2.new(0.5, -1, 0, 0)
  472. Frame17.BackgroundColor3 = Color3.new(0, 0, 0)
  473. Frame17.BorderColor3 = Color3.new(0, 0, 0)
  474. Frame17.BorderSizePixel = 0
  475. Frame18.Name = "Crosshair"
  476. Frame18.Parent = ScreenGui10
  477. Frame18.Size = UDim2.new(0, 2, 0, 2)
  478. Frame18.Position = UDim2.new(0.5, -1, 0.5, -16)
  479. Frame18.BackgroundColor3 = Color3.new(1, 0, 0)
  480. Frame18.BorderColor3 = Color3.new(0, 0, 0)
  481. Frame18.BorderSizePixel = 0
  482. Sound19.Name = "HeadshotPlayer1"
  483. Sound19.Parent = Tool0
  484. Sound19.SoundId = "rbxassetid://178070151"
  485. Sound19.Volume = 1
  486. Sound20.Name = "HeadshotPlayer2"
  487. Sound20.Parent = Tool0
  488. Sound20.SoundId = "rbxassetid://178072179"
  489. Sound20.Volume = 1
  490. BoolValue21.Name = "AimDown"
  491. BoolValue21.Parent = Tool0
  492. for i,v in pairs(mas:GetChildren()) do
  493. v.Parent = owner.Backpack
  494. pcall(function() v:MakeJoints() end)
  495. end
  496. mas:Destroy()
  497. for i,v in pairs(cors) do
  498. spawn(function()
  499. pcall(v)
  500. end)
  501. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement