Advertisement
SCR1PT_ED1T0R

FE Portal Gun

Sep 3rd, 2018
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  2. local Player,Mouse,mouse,UserInputService,ContextActionService = owner
  3. do
  4. print("FE Compatibility code by Mokiros")
  5. script.Parent = Player.Character
  6.  
  7. --RemoteEvent for communicating
  8. local Event = Instance.new("RemoteEvent")
  9. Event.Name = "UserInput_Event"
  10.  
  11. --Fake event to make stuff like Mouse.KeyDown work
  12. local function fakeEvent()
  13. local t = {_fakeEvent=true,Connect=function(self,f)self.Function=f end}
  14. t.connect = t.Connect
  15. return t
  16. end
  17.  
  18. --Creating fake input objects with fake variables
  19. local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
  20. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  21. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  22. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  23. end}
  24. --Merged 2 functions into one by checking amount of arguments
  25. CAS.UnbindAction = CAS.BindAction
  26.  
  27. --This function will trigger the events that have been :Connect()'ed
  28. local function te(self,ev,...)
  29. local t = m[ev]
  30. if t and t._fakeEvent and t.Function then
  31. t.Function(...)
  32. end
  33. end
  34. m.TrigEvent = te
  35. UIS.TrigEvent = te
  36.  
  37. Event.OnServerEvent:Connect(function(plr,io)
  38. if plr~=Player then return end
  39. if io.isMouse then
  40. m.Target = io.Target
  41. m.Hit = io.Hit
  42. else
  43. local b = io.UserInputState == Enum.UserInputState.Begin
  44. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  45. return m:TrigEvent(b and "Button1Down" or "Button1Up")
  46. end
  47. for _,t in pairs(CAS.Actions) do
  48. for _,k in pairs(t.Keys) do
  49. if k==io.KeyCode then
  50. t.Function(t.Name,io.UserInputState,io)
  51. end
  52. end
  53. end
  54. m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  55. UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
  56. end
  57. end)
  58. Event.Parent = NLS([==[
  59. local Player = game:GetService("Players").LocalPlayer
  60. local Event = script:WaitForChild("UserInput_Event")
  61.  
  62. local UIS = game:GetService("UserInputService")
  63. local input = function(io,a)
  64. if a then return end
  65. --Since InputObject is a client-side instance, we create and pass table instead
  66. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState})
  67. end
  68. UIS.InputBegan:Connect(input)
  69. UIS.InputEnded:Connect(input)
  70.  
  71. local Mouse = Player:GetMouse()
  72. local h,t
  73. --Give the server mouse data 30 times every second, but only if the values changed
  74. --If player is not moving their mouse, client won't fire events
  75. while wait(1/30) do
  76. if h~=Mouse.Hit or t~=Mouse.Target then
  77. h,t=Mouse.Hit,Mouse.Target
  78. Event:FireServer({isMouse=true,Target=t,Hit=h})
  79. end
  80. end]==],Player.Character)
  81. Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
  82. end
  83. Player = owner
  84. gun = Instance.new("Part", owner.Character)
  85. gun.Size = Vector3.new(0.5, 1, 2)
  86. gun.CanCollide = false
  87. gun:BreakJoints()
  88. weld = Instance.new("Weld", gun)
  89. weld.Part0 = owner.Character["Right Arm"]
  90. weld.Part1 = gun
  91. mesh = Instance.new("SpecialMesh", gun)
  92. mesh.MeshId = "rbxassetid://430056568"
  93. mesh.TextureId = "rbxassetid://430056584"
  94. portalmoosic = Instance.new("Sound", owner.Character)
  95. portalmoosic.SoundId = "rbxassetid://142300248"
  96. portalmoosic.Looped = true
  97. portalmoosic:Play()
  98. impact = Instance.new("Sound", owner.Character)
  99. impact.SoundId = "rbxassetid://142082170"
  100. mesh.Scale = Vector3.new(0.17,0.17,0.17)
  101. weld.C0 = weld.C0 * CFrame.new(-0.2,-1.3,-0.8) * CFrame.Angles(3,0,0)
  102. local rhandweld = Instance.new("Weld", owner.Character.Torso)
  103. rhandweld.Part0 = owner.Character.Torso
  104. rhandweld.Part1 = owner.Character["Right Arm"]
  105. rhandweld.C0 = CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
  106. rhandweld.C1 = CFrame.new(0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
  107. local lhandweld = Instance.new("Weld", owner.Character.Torso)
  108. lhandweld.Part0 = owner.Character.Torso
  109. lhandweld.Part1 = owner.Character["Left Arm"]
  110. lhandweld.C0 = CFrame.new(-1.5, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  111. lhandweld.C1 = CFrame.new(0, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  112. Pick = Instance.new("Sound", gun)
  113. Pick.SoundId = "rbxassetid://291256829"
  114. Pick:Play()
  115. Shoot = Instance.new("Sound", gun)
  116. Shoot.SoundId = "rbxassetid://142774034"
  117. blueexists = false
  118. tping = false
  119. orangeexists = false
  120. for i = 0,1 , 0.1 do
  121. wait()
  122. lhandweld.C0 = lhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,-0.2,-0.28),i)
  123. rhandweld.C0 = rhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,0.28),i)
  124. end
  125. for i = 0,1 , 0.1 do
  126. wait()
  127. lhandweld.C0 = lhandweld.C0 * CFrame.new():lerp(CFrame.new(0,-0.25,0),i)
  128. end
  129. using = false
  130. orange = false
  131. blue = true
  132. function changeportals(key)
  133. key = key:lower()
  134. if key == "q" then
  135. if not blue then
  136. blue = true
  137. orange = false
  138. end
  139. end
  140. if key == "e" then
  141. if not orange then
  142. blue = false
  143. orange = true
  144. end
  145. end
  146. end
  147. function portal()
  148. if not using then
  149. using = true
  150. if blue then
  151. Shoot:Play()
  152. local projectile = Instance.new("Part", workspace)
  153. projectile.Size = Vector3.new(1,1,1)
  154. projectile.BrickColor = BrickColor.new("Electric blue")
  155. projectile.Shape = "Ball"
  156. projectile.CanCollide = true
  157. projectile.Anchored = false
  158. projectile.Material = "Neon"
  159. local vel = Instance.new("BodyVelocity", projectile)
  160. vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  161. vel.Velocity = mouse.Hit.lookVector * 80
  162. projectile.Position = gun.CFrame.p
  163. wait(0.03)
  164. local function make(part)
  165. local gr = part.Parent:findFirstChild("Part")
  166. local porjectileposition = projectile.Position
  167. local portaldoor = Instance.new("Part", workspace)
  168. portaldoor.Size = Vector3.new(1, 1, 1)
  169. portaldoor.BrickColor = BrickColor.new("Electric blue")
  170. portaldoor.Anchored = true
  171. portaldoor.Shape = "Cylinder"
  172. portaldoor.Material = "Neon"
  173. portaldoor.CanCollide = false
  174. if blueexists == true then
  175. workspace.BluePortal:destroy()
  176. end
  177. blueexists = true
  178. portaldoor.Name = "BluePortal"
  179. portaldoor.CFrame = part.CFrame
  180. if part.Size.y < part.Size.x and part.Size.y < part.Size.z then --a big help from Toxsikkilla
  181. print("if y < x")
  182. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(0,0,math.pi / 2)
  183. elseif part.Size.x < part.Size.y and part.Size.x < part.Size.z then
  184. print("if x < y")
  185. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(math.pi / 2, 0, 0)
  186. elseif part.Size.z < part.Size.y and part.Size.z < part.Size.y then
  187. print("if z < y")
  188. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(0, math.pi / 2, 0)
  189. end
  190. portaldoor.Position = projectile.Position
  191. projectile:destroy()
  192. for i = 1,18 do
  193. portaldoor.Size = portaldoor.Size + Vector3.new(0,0.3,0.3)
  194. wait()
  195. end
  196. local function tp(part)
  197. local hum = part.Parent:findFirstChild("Humanoid")
  198. if hum ~= nil and blueexists and orangeexists and not tping then
  199. tping = true
  200. local tor = part.Parent:findFirstChild("Torso")
  201. if tor then
  202. local velocityoftorso = tor.Velocity
  203. local blport = workspace:findFirstChild("OrangePortal")
  204. if blport then
  205. tor.CFrame = workspace.OrangePortal.CFrame
  206. tor.Velocity = workspace.OrangePortal.CFrame.rightVector * -velocityoftorso * 1.7
  207. end
  208. end
  209. wait(0.3)
  210. tping = false
  211. end
  212. if not hum and blueexists and orangeexists and not tping then
  213. tping = true
  214. local cube = part.Parent:findFirstChild("Cube")
  215. if cube then
  216. tping = true
  217. local velocityoftorso = cube.Velocity
  218. cube.CFrame = workspace.OrangePortal.CFrame
  219. cube.Velocity = workspace.OrangePortal.CFrame.rightVector * -velocityoftorso * 1.7
  220. wait(0.3)
  221. tping = false
  222. end
  223. end
  224. wait(0.3)
  225. tping = false
  226. end
  227. portaldoor.Touched:connect(tp)
  228. end
  229. projectile.Touched:connect(make)
  230. end
  231. if orange then
  232. Shoot:Play()
  233. local projectile1 = Instance.new("Part", workspace)
  234. projectile1.Size = Vector3.new(1,1,1)
  235. projectile1.BrickColor = BrickColor.new("Deep orange")
  236. projectile1.Shape = "Ball"
  237. projectile1.CanCollide = true
  238. projectile1.Anchored = false
  239. projectile1.Material = "Neon"
  240. local vel1 = Instance.new("BodyVelocity", projectile1)
  241. vel1.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  242. vel1.Velocity = mouse.Hit.lookVector * 80
  243. projectile1.Position = gun.CFrame.p
  244. wait(0.03)
  245. local function make1(part)
  246. local gr = part.Parent:findFirstChild("Part")
  247. local portaldoor = Instance.new("Part", workspace)
  248. portaldoor.Size = Vector3.new(1, 1, 1)
  249. portaldoor.BrickColor = BrickColor.new("Deep orange")
  250. portaldoor.Anchored = true
  251. portaldoor.Material = "Neon"
  252. portaldoor.Shape = "Cylinder"
  253. portaldoor.CanCollide = false
  254. if orangeexists == true then
  255. workspace.OrangePortal:destroy()
  256. end
  257. portaldoor.CFrame = part.CFrame
  258. if part.Size.y < part.Size.x and part.Size.y < part.Size.z then --a big help from Toxsikkilla
  259. print("if y < x")
  260. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(0,0,math.pi / 2)
  261. elseif part.Size.x < part.Size.y and part.Size.x < part.Size.z then
  262. print("if x < y")
  263. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(math.pi / 2, 0, 0)
  264. elseif part.Size.z < part.Size.y and part.Size.z < part.Size.y then
  265. print("if z < y")
  266. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(0, math.pi / 2, 0)
  267. end
  268. portaldoor.Position = projectile1.Position
  269. projectile1:destroy()
  270. for i = 1,18 do
  271. portaldoor.Size = portaldoor.Size + Vector3.new(0,0.3,0.3)
  272. wait()
  273. end
  274. orangeexists = true
  275. portaldoor.Name = "OrangePortal"
  276. local function tp(part)
  277. local hum = part.Parent:findFirstChild("Humanoid")
  278. if hum ~= nil and blueexists and orangeexists and not tping then
  279. tping = true
  280. local tor = part.Parent:findFirstChild("Torso")
  281. if tor then
  282. local velocityoftorso = tor.Velocity
  283. local blport = workspace:findFirstChild("BluePortal")
  284. if blport then
  285. tor.CFrame = workspace.BluePortal.CFrame
  286. tor.Velocity = workspace.BluePortal.CFrame.rightVector * -velocityoftorso * 1.7
  287. end
  288. end
  289. wait(0.3)
  290. tping = false
  291. end
  292. if not hum and blueexists and orangeexists and not tping then
  293. tping = true
  294. local cube = part.Parent:findFirstChild("Cube")
  295. if cube then
  296. tping = true
  297. local velocityoftorso = cube.Velocity
  298. local blport = workspace:findFirstChild("BluePortal")
  299. if velocityoftorso.y < velocityoftorso.z and velocityoftorso.y < velocityoftorso.x then
  300. cube.Velocity = -velocityoftorso * 1.5
  301. if blport then
  302. cube.CFrame = workspace.BluePortal.rightVector * -velocityoftorso * 1.7
  303. end
  304. end
  305. wait(0.3)
  306. tping = false
  307. end
  308. wait(0.3)
  309. tping = false
  310. end
  311. wait(0.3)
  312. tping = false
  313. end
  314. portaldoor.Touched:connect(tp)
  315. end
  316. projectile1.Touched:connect(make1)
  317. end
  318.  
  319. for i = 0,1 , 0.3 do
  320. wait()
  321. lhandweld.C0 = lhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,-0.2),i)
  322. rhandweld.C0 = rhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,0.2),i)
  323. end
  324. for i = 0,1 , 0.3 do
  325. wait()
  326. lhandweld.C0 = lhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,0.2),i)
  327. rhandweld.C0 = rhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,-0.2),i)
  328. end
  329. using = false
  330. end
  331. end
  332. function remove(key)
  333. key = key:lower()
  334. if key == "r" then
  335. if blueexists or orangeexists or blueexists and orangeexists then
  336. workspace.OrangePortal:destroy()
  337. workspace.BluePortal:destroy()
  338. orangeexists = false
  339. blueexists = false
  340. end
  341. end
  342. end
  343. impacting = false
  344. cubesp = false
  345. function cubespawn(key)
  346. key = key:lower()
  347. if key == "c" then
  348. if cubesp then
  349. workspace.Cube:destroy()
  350. end
  351. cubesp = true
  352. local coobe = Instance.new("Part", workspace)
  353. coobe.Size = Vector3.new(2.774, 2.834, 2.804)
  354. coobe:BreakJoints()
  355. coobe.Position = game.Players.LocalPlayer.Character.Torso.Position
  356. coobe.Name = "Cube"
  357. local meh = Instance.new("SpecialMesh", coobe)
  358. meh.MeshId = "rbxassetid://464957313"
  359. meh.TextureId = "rbxassetid://464957325"
  360. meh.Scale = Vector3.new(0.8,0.8,0.8)
  361. local function sounds()
  362. if not impacting then
  363. impacting = true
  364. local impactspeed = math.random(0.9,1.1)
  365. impact.PlaybackSpeed = impactspeed
  366. impact:Play()
  367. wait(0.2)
  368. impacting = false
  369. end
  370. end
  371. coobe.Touched:connect(sounds)
  372. end
  373. end
  374. function deleterportalsondedth()
  375. if orangeexists or blueexists or blueexists and orangeexists then
  376. workspace.OrangePortal:destroy()
  377. workspace.BluePortal:destroy()
  378. if cubesp then
  379. workspace.Cube:destroy()
  380. end
  381. end
  382. end
  383. owner.Character.Humanoid.Died:connect(deleterportalsondedth)
  384. mouse.KeyDown:connect(cubespawn)
  385. mouse.Button1Down:connect(portal)
  386. mouse.KeyDown:connect(changeportals)
  387. mouse.KeyDown:connect(remove)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement