Advertisement
-----------------

guided missile launcher

Feb 20th, 2021
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.06 KB | None | 0 0
  1. --https://github.com/Mokiros/roblox-FE-compatibility
  2. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  3. local Player,game,owner = owner,game
  4. local RealPlayer = Player
  5. do
  6. print("FE Compatibility code V2 by Mokiros")
  7. local RealPlayer = RealPlayer
  8. script.Parent = RealPlayer.Character
  9.  
  10. --Fake event to make stuff like Mouse.KeyDown work
  11. local Disconnect_Function = function(this)
  12. this[1].Functions[this[2]] = nil
  13. end
  14. local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
  15. local FakeEvent_Metatable = {__index={
  16. Connect = function(this,f)
  17. local i = tostring(math.random(0,10000))
  18. while this.Functions[i] do
  19. i = tostring(math.random(0,10000))
  20. end
  21. this.Functions[i] = f
  22. return setmetatable({this,i},Disconnect_Metatable)
  23. end
  24. }}
  25. FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
  26. local function fakeEvent()
  27. return setmetatable({Functions={}},FakeEvent_Metatable)
  28. end
  29.  
  30. --Creating fake input objects with fake variables
  31. local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
  32. FakeMouse.keyUp = FakeMouse.KeyUp
  33. FakeMouse.keyDown = FakeMouse.KeyDown
  34. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  35. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  36. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  37. end}
  38. --Merged 2 functions into one by checking amount of arguments
  39. CAS.UnbindAction = CAS.BindAction
  40.  
  41. --This function will trigger the events that have been :Connect()'ed
  42. local function TriggerEvent(self,ev,...)
  43. for _,f in pairs(self[ev].Functions) do
  44. f(...)
  45. end
  46. end
  47. FakeMouse.TriggerEvent = TriggerEvent
  48. UIS.TriggerEvent = TriggerEvent
  49.  
  50. --Client communication
  51. local Event = Instance.new("RemoteEvent")
  52. Event.Name = "UserInput_Event"
  53. Event.OnServerEvent:Connect(function(plr,io)
  54. if plr~=RealPlayer then return end
  55. FakeMouse.Target = io.Target
  56. FakeMouse.Hit = io.Hit
  57. if not io.isMouse then
  58. local b = io.UserInputState == Enum.UserInputState.Begin
  59. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  60. return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
  61. end
  62. if io.UserInputType == Enum.UserInputType.MouseButton2 then
  63. return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
  64. end
  65. for _,t in pairs(CAS.Actions) do
  66. for _,k in pairs(t.Keys) do
  67. if k==io.KeyCode then
  68. t.Function(t.Name,io.UserInputState,io)
  69. end
  70. end
  71. end
  72. FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  73. UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
  74. end
  75. end)
  76. Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
  77. local Mouse = owner:GetMouse()
  78. local UIS = game:GetService("UserInputService")
  79. local input = function(io,RobloxHandled)
  80. if RobloxHandled then return end
  81. --Since InputObject is a client-side instance, we create and pass table instead
  82. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
  83. end
  84. UIS.InputBegan:Connect(input)
  85. UIS.InputEnded:Connect(input)
  86.  
  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. wait(1)
  153. local debris = game:GetService("Debris")
  154. local playerservice = game:GetService("Players")
  155. local xplayer = playerservice.LocalPlayer
  156. repeat wait(.5) until xplayer ~= nil
  157. local xcharacter = xplayer.Character
  158. local playermouse = xplayer:GetMouse()
  159. local playercam = workspace.CurrentCamera
  160. local playercharacter = xplayer.Character
  161.  
  162. repeat wait(.5) until xplayer.Character ~=nil
  163.  
  164. local xhumanoid = xcharacter:WaitForChild('Humanoid')
  165. local rltool = Instance.new("Tool")
  166. rltool.Name = 'GuidedMissile'
  167. rltool.GripForward = Vector3.new(0,0,-1)
  168. rltool.GripPos = Vector3.new(0.05,-0.6,-1)
  169. rltool.GripRight = Vector3.new(1,0,0)
  170. rltool.GripUp = Vector3.new(0,1,0)
  171. rltool.ToolTip = 'Launch the rocket and you will begin controlling the rocket'
  172. local handle = Instance.new("Part",rltool)
  173. handle.Name = "Handle"
  174. handle.Material = 'Plastic'
  175. handle.CanCollide = true
  176. handle.Locked = true
  177. handle.Size = Vector3.new(0.84,1.15,3.55)
  178. handle.TopSurface = 'Smooth'
  179. handle.BottomSurface = 'Smooth'
  180. local handlemesh = Instance.new("SpecialMesh",handle)
  181. handlemesh.MeshType = Enum.MeshType.FileMesh
  182. handlemesh.MeshId = "http://www.roblox.com/asset/?id=94690054"
  183. handlemesh.TextureId = "http://www.roblox.com/asset/?id=94689966"
  184. handlemesh.Scale = Vector3.new(1.5,1.5,1.5)
  185.  
  186. local MainTool = rltool
  187. local AmmoSize = 1
  188. local CurrentAmmo = 1
  189. local AmmoMax = math.huge
  190. local ToolEnabled = true
  191. local GuidedRocket = false
  192. local camerafollow = xhumanoid
  193. BaseRocket = nil
  194. local cooldown = 4
  195. local RocketSpeed = 75
  196.  
  197. local newsound = Instance.new("Sound")
  198. newsound.Name = 'NewSound'
  199. newsound.Volume = 1
  200. newsound.PlaybackSpeed = 1
  201. newsound.EmitterSize = 10
  202. newsound.MaxDistance = 10000
  203. newsound.Looped = false
  204.  
  205. MainTool.Parent = xplayer.Backpack
  206.  
  207. local RocketSize = Vector3.new(1,1,4)
  208.  
  209. function CreateBaseRocket()
  210. local rocket = Instance.new("Part")
  211. rocket.Name = "Rocket"
  212. rocket.Size = RocketSize
  213. rocket.CanCollide = false
  214. rocket.BottomSurface = 'Smooth'
  215. rocket.TopSurface = 'Smooth'
  216. rocket.BrickColor = BrickColor.Random()
  217. local specialmesh = Instance.new("SpecialMesh",rocket)
  218. specialmesh.MeshType = Enum.MeshType.FileMesh
  219. specialmesh.Scale = Vector3.new(.5,.5,.2)
  220. specialmesh.MeshId = "http://www.roblox.com/asset/?id=2251534"
  221. local attachmentr1 = Instance.new("Attachment",rocket)
  222. attachmentr1.Name = 'R0'
  223. attachmentr1.Position = Vector3.new(-1,0,-1)
  224. local attachmentr2 = attachmentr1:Clone()
  225. attachmentr2.Name = 'R1'
  226. attachmentr2.Position = Vector3.new(1,0,1)
  227. attachmentr2.Parent = rocket
  228. local trail = Instance.new("Trail",rocket)
  229. trail.LightEmission = .75
  230. trail.Color = ColorSequence.new(Color3.new(255/255,0,0),Color3.new(255/255,120/255,0))
  231. trail.Attachment0 = attachmentr1
  232. trail.Attachment1 = attachmentr2
  233. trail.MaxLength = 15
  234. trail.MinLength = .1
  235. trail.Lifetime = 4.5
  236. trail.Transparency = NumberSequence.new({
  237. NumberSequenceKeypoint.new(0,0.0);
  238. NumberSequenceKeypoint.new(.858,.081);
  239. NumberSequenceKeypoint.new(.958,.181);
  240. NumberSequenceKeypoint.new(1,1.0);
  241. })
  242. --[[local bodyForce = Instance.new('BodyForce', rocket)
  243. bodyForce.Name = 'Antigravity'
  244. bodyForce.force = Vector3.new(0, rocket:GetMass() * workspace.Gravity, 0)]]
  245.  
  246. BaseRocket = rocket
  247. end
  248.  
  249. function ToolEquipped()
  250. CreateBaseRocket()
  251.  
  252. if GuidedRocket == true then
  253. MainTool.Enabled = false
  254. end
  255. if GuidedRocket == false then
  256. MainTool.Enabled = true
  257. end
  258.  
  259. end
  260.  
  261. --[[function ControlRocket(main,Control_OBJ,Target_Position)
  262.  
  263. Control_OBJ.TargetOffset = Target_Position
  264.  
  265. end]]
  266.  
  267. function ToolActivated()
  268. if ToolEnabled== true and xcharacter and xhumanoid.Health > 0 then
  269. local targetPosition = xhumanoid.TargetPoint
  270. ToolEnabled = false
  271.  
  272. local SwooshSound = newsound:Clone()
  273. SwooshSound.PlaybackSpeed = .5
  274. SwooshSound.SoundId = "http://www.roblox.com/Asset?ID=132456187"
  275. SwooshSound.Name = 'Swoosh'
  276. SwooshSound.Volume = 1
  277. SwooshSound.Looped = true
  278.  
  279. local BoomSound = newsound:Clone()
  280. BoomSound.PlaybackSpeed = .7
  281. BoomSound.Volume = 3
  282. BoomSound.PlayOnRemove = true
  283. BoomSound.SoundId = "http://www.roblox.com/Asset?ID=138186576"
  284. BoomSound.Name = 'Boom'
  285. BoomSound.Looped = false
  286.  
  287.  
  288. local GRocket = BaseRocket:Clone()
  289.  
  290. local RocketControl = Instance.new("RocketPropulsion",GRocket)
  291. RocketControl.CartoonFactor = 1
  292. RocketControl.MaxSpeed = RocketSpeed
  293. RocketControl.TargetOffset = targetPosition
  294. RocketControl.ThrustD = 50000
  295. RocketControl.ThrustP = 500
  296. RocketControl.TargetRadius = 5
  297. RocketControl.MaxThrust = 50000
  298. RocketControl.MaxTorque = Vector3.new(4e6, 4e6, 0)
  299.  
  300. local spawnPosition = (handle.CFrame * CFrame.new(0, 0, -4)).p
  301. GRocket.CFrame = CFrame.new(spawnPosition, targetPosition)
  302. GRocket.Velocity = GRocket.CFrame.lookVector * RocketSpeed
  303.  
  304. SwooshSound.Parent = GRocket
  305. BoomSound.Parent = GRocket
  306. debris:AddItem(GRocket,20)
  307. GRocket.Parent = workspace
  308. playercam.CameraSubject = GRocket
  309. RocketControl:Fire()
  310.  
  311. SwooshSound.Playing = false
  312. wait(.15)
  313. wait(.15)
  314. SwooshSound:Play()
  315.  
  316.  
  317. GRocket.Touched:connect(function(part)
  318. if part and GRocket then
  319. if part.Parent then
  320. if part.Parent and part.Parent.Name ~= xcharacter.Name then
  321. local Explosion = Instance.new("Explosion",workspace)
  322. Explosion.Position = GRocket.Position
  323. Explosion.BlastPressure = 100000
  324. Explosion.BlastRadius = 14
  325. Explosion.ExplosionType = Enum.ExplosionType.CratersAndDebris
  326. GuidedRocket = false
  327. playercam.CameraSubject = xhumanoid
  328. GRocket:Destroy()
  329. end
  330. end
  331. end
  332. end)
  333.  
  334. GuidedRocket = true
  335.  
  336. playermouse.Move:Connect(function()
  337. if GuidedRocket == true then
  338. playermouse.TargetFilter = GRocket
  339. RocketControl.TargetOffset = Vector3.new(playermouse.Hit.X,playermouse.Hit.Y,playermouse.Hit.Z)
  340. end
  341. end)
  342.  
  343. if GRocket.Parent ~= nil and GuidedRocket==true then
  344. print('Controlling the rocket')
  345. end
  346. repeat wait(1) until GRocket.Parent == nil
  347. GuidedRocket = false
  348. playermouse.TargetFilter = nil
  349. playercam.CameraSubject = xhumanoid
  350. GuidedRocket = false
  351. wait(3)
  352. GuidedRocket = false
  353. ToolEnabled = true
  354. end
  355. end
  356.  
  357. function PlayerDied()
  358. if GuidedRocket == true and playercam.CameraSubject ~= xhumanoid then
  359. GuidedRocket = false
  360. playercam.CameraSubject = xhumanoid
  361. ToolEnabled = false
  362. MainTool.Enabled = false
  363. end
  364. if playercam.CameraSubject ~= xhumanoid then
  365. ToolEnabled = false
  366. MainTool.Enabled = false
  367. playercam.CameraSubject = xhumanoid
  368. GuidedRocket = false
  369. end
  370. end
  371. function ToolUnequipped()
  372. MainTool.Enabled = false
  373. end
  374.  
  375. MainTool.Equipped:Connect(ToolEquipped)
  376. MainTool.Unequipped:Connect(ToolUnequipped)
  377. MainTool.Activated:Connect(ToolActivated)
  378. xhumanoid.Died:Connect(PlayerDied)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement