StarzoZero

roblox portal gun script

Jan 13th, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.44 KB | None | 0 0
  1. if game:GetService("RunService"):IsClient()then error("Please run as a server script. Use h/ instead of hl/.")end;print("FE Compatibility: by StarzoZero");InternalData = {}
  2. do
  3. script.Parent = owner.Character
  4. local Event = Instance.new("RemoteEvent");Event.Name = "UserInput"
  5. local function NewFakeEvent()
  6. local Bind = Instance.new("BindableEvent")
  7. local Fake;Fake = {Connections = {},
  8. fakeEvent=true;
  9. Connect=function(self,Func)
  10. Bind.Event:connect(Func)
  11. self.Connections[Bind] = true
  12. return setmetatable({Connected = true},{
  13. __index = function (self,Index)
  14. if Index:lower() == "disconnect" then
  15. return function() Fake.Connections[Bind] = false;self.Connected = false end
  16. end
  17. return Fake[Index]
  18. end;
  19. __tostring = function() return "Connection" end;
  20. })
  21. end}
  22. Fake.connect = Fake.Connect;return Fake;
  23. end
  24. local Mouse = {Target=nil,Hit=CFrame.new(),KeyUp=NewFakeEvent(),KeyDown=NewFakeEvent(),Button1Up=NewFakeEvent(),Button1Down=NewFakeEvent()}
  25. local UserInputService = {InputBegan=NewFakeEvent(),InputEnded=NewFakeEvent()}
  26. local ContextActionService = {Actions={},BindAction = function(self,actionName,Func,touch,...)
  27. self.Actions[actionName] = Func and {Name=actionName,Function=Func,Keys={...}} or nil
  28. end};ContextActionService.UnBindAction = ContextActionService.BindAction
  29. local function TriggerEvent(self,Event,...)
  30. local Trigger = Mouse[Event]
  31. if Trigger and Trigger.fakeEvent and Trigger.Connections then
  32. for Connection,Active in pairs(Trigger.Connections) do if Active then Connection:Fire(...) end end
  33. end
  34. end
  35. Mouse.TrigEvent = TriggerEvent;UserInputService.TrigEvent = TriggerEvent
  36. Event.OnServerEvent:Connect(function(FiredBy,Input)
  37. if FiredBy.Name ~= owner.Name then return end
  38. if Input.MouseEvent then
  39. Mouse.Target = Input.Target;Mouse.Hit = Input.Hit
  40. else
  41. local Begin = Input.UserInputState == Enum.UserInputState.Begin
  42. if Input.UserInputType == Enum.UserInputType.MouseButton1 then return Mouse:TrigEvent(Begin and "Button1Down" or "Button1Up") end
  43. for _,Action in pairs(ContextActionService.Actions) do
  44. for _,Key in pairs(Action.Keys) do if Key==Input.KeyCode then Action.Function(Action.Name,Input.UserInputState,Input) end end
  45. end
  46. Mouse:TrigEvent(Begin and "KeyDown" or "KeyUp",Input.KeyCode.Name:lower())
  47. UserInputService:TrigEvent(Begin and "InputBegan" or "InputEnded",Input,false)
  48. end
  49. end)
  50. InternalData["Mouse"] = Mouse;InternalData["ContextActionService"] = ContextActionService;InternalData["UserInputService"] = UserInputService
  51. Event.Parent = NLS([[
  52. local Player = owner;local Event = script:WaitForChild("UserInput");local UserInputService = game:GetService("UserInputService");local Mouse = Player:GetMouse()
  53. local Input = function(Input,gameProcessedEvent)
  54. if gameProcessedEvent then return end
  55. Event:FireServer({KeyCode=Input.KeyCode,UserInputType=Input.UserInputType,UserInputState=Input.UserInputState})
  56. end
  57. UserInputService.InputBegan:Connect(Input);UserInputService.InputEnded:Connect(Input)
  58. local Hit,Target
  59. while wait(1/30) do
  60. if Hit ~= Mouse.Hit or Target ~= Mouse.Target then
  61. Hit,Target = Mouse.Hit,Mouse.Target;Event:FireServer({["MouseEvent"]=true,["Target"]=Target,["Hit"]=Hit})
  62. end
  63. end
  64. ]],owner.Character)
  65. end
  66. RealGame = game;game = setmetatable({},{
  67. __index = function (self,Index)
  68. local Sandbox = function (Thing)
  69. if Thing:IsA("Player") then
  70. local RealPlayer = Thing
  71. return setmetatable({},{
  72. __index = function (self,Index)
  73. local Type = type(RealPlayer[Index])
  74. if Type == "function" then
  75. if Index:lower() == "getmouse" or Index:lower() == "mouse" then
  76. return function (self)return InternalData["Mouse"] end
  77. end
  78. return function (self,...)return RealPlayer[Index](RealPlayer,...) end
  79. end
  80. return RealPlayer[Index]
  81. end;
  82. __tostring = function(self) return RealPlayer.Name end
  83. })
  84. end
  85. end
  86. if RealGame[Index] then
  87. local Type = type(RealGame[Index])
  88. if Type == "function" then
  89. if Index:lower() == "getservice" or Index:lower() == "service" then
  90. return function (self,Service)
  91. local FakeServices = {
  92. ["players"] = function()
  93. return setmetatable({},{
  94. __index = function (self2,Index2)
  95. local RealService = RealGame:GetService(Service)
  96. local Type2 = type(Index2)
  97. if Type2 == "function" then
  98. return function (self,...) return RealService[Index2](RealService,...)end
  99. else
  100. if Index2:lower() == "localplayer" then return Sandbox(owner) end
  101. return RealService[Index2]
  102. end
  103. end;
  104. __tostring = function(self) return RealGame:GetService(Service).Name end
  105. })
  106. end;
  107. ["contextactionservice"] = function() return InternalData["ContextActionService"] end;
  108. ["userinputservice"] = function() return InternalData["UserInputService"] end;
  109. ["runservice"] = function()
  110. return setmetatable({},{
  111. __index = function(self2,Index2)
  112. local RealService = RealGame:GetService(Service)
  113. local Type2 = type(Index2)
  114. if Type2 == "function" then
  115. return function (self,...) return RealService[Index2](RealService,...) end
  116. else
  117. local RunServices = {
  118. ["bindtorenderstep"] = function() return function (self,Name,Priority,Function) return RealGame:GetService("RunService").Stepped:Connect(Function) end end;
  119. ["renderstepped"] = function() return RealService["Stepped"] end
  120. }
  121. if RunServices[Index2:lower()] then return RunServices[Index2:lower()]() end
  122. return RealService[Index2]
  123. end
  124. end
  125. })
  126. end
  127. }
  128. if FakeServices[Service:lower()] then return FakeServices[Service:lower()]() end
  129. return RealGame:GetService(Service)
  130. end
  131. end
  132. return function (self,...) return RealGame[Index](RealGame,...) end
  133. else
  134. if game:GetService(Index) then return game:GetService(Index) end
  135. return RealGame[Index]
  136. end
  137. end
  138. return nil
  139. end
  140. });Game = game;owner = game:GetService("Players").LocalPlayer;script = Instance.new("Script");print("You monster.")
  141.  
  142. mouse = game.Players.LocalPlayer:GetMouse()
  143. gun = Instance.new("Part", game.Players.LocalPlayer.Character)
  144. gun.Size = Vector3.new(0.5, 1, 2)
  145. gun.CanCollide = false
  146. gun:BreakJoints()
  147. weld = Instance.new("Weld", gun)
  148. weld.Part0 = game.Players.LocalPlayer.Character["Right Arm"]
  149. weld.Part1 = gun
  150. mesh = Instance.new("SpecialMesh", gun)
  151. mesh.MeshId = "rbxassetid://430056568"
  152. mesh.TextureId = "rbxassetid://430056584"
  153. portalmoosic = Instance.new("Sound", game.Players.LocalPlayer.Character)
  154. portalmoosic.SoundId = "rbxassetid://173064565"
  155. portalmoosic.Looped = true
  156. portalmoosic:Play()
  157. mesh.Scale = Vector3.new(0.17,0.17,0.17)
  158. weld.C0 = weld.C0 * CFrame.new(-0.2,-1.3,-0.8) * CFrame.Angles(3,0,0)
  159. local rhandweld = Instance.new("Weld", game.Players.LocalPlayer.Character.Torso)
  160. rhandweld.Part0 = game.Players.LocalPlayer.Character.Torso
  161. rhandweld.Part1 = game.Players.LocalPlayer.Character["Right Arm"]
  162. rhandweld.C0 = CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
  163. rhandweld.C1 = CFrame.new(0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
  164. local lhandweld = Instance.new("Weld", game.Players.LocalPlayer.Character.Torso)
  165. lhandweld.Part0 = game.Players.LocalPlayer.Character.Torso
  166. lhandweld.Part1 = game.Players.LocalPlayer.Character["Left Arm"]
  167. lhandweld.C0 = CFrame.new(-1.5, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  168. lhandweld.C1 = CFrame.new(0, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  169. Pick = Instance.new("Sound", gun)
  170. Pick.SoundId = "rbxassetid://291256829"
  171. Pick:Play()
  172. Shoot = Instance.new("Sound", gun)
  173. Shoot.SoundId = "rbxassetid://142774034"
  174. blueexists = false
  175. tping = false
  176. orangeexists = false
  177. for i = 0,1 , 0.1 do
  178. wait()
  179. lhandweld.C0 = lhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,-0.2,-0.28),i)
  180. rhandweld.C0 = rhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,0.28),i)
  181. end
  182. for i = 0,1 , 0.1 do
  183. wait()
  184. lhandweld.C0 = lhandweld.C0 * CFrame.new():lerp(CFrame.new(0,-0.25,0),i)
  185. end
  186. using = false
  187. orange = false
  188. blue = true
  189. function changeportals(key)
  190. key = key:lower()
  191. if key == "q" then
  192. if not blue then
  193. blue = true
  194. orange = false
  195. end
  196. end
  197. if key == "e" then
  198. if not orange then
  199. blue = false
  200. orange = true
  201. end
  202. end
  203. end
  204. function portal()
  205. if not using then
  206. using = true
  207. if blue then
  208. Shoot:Play()
  209. local projectile = Instance.new("Part", workspace)
  210. projectile.Size = Vector3.new(1,1,1)
  211. projectile.BrickColor = BrickColor.new("Electric blue")
  212. projectile.Shape = "Ball"
  213. projectile.CanCollide = true
  214. projectile.Anchored = false
  215. projectile.Material = "Neon"
  216. local vel = Instance.new("BodyVelocity", projectile)
  217. vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  218. vel.Velocity = mouse.Hit.lookVector * 80
  219. projectile.Position = gun.CFrame.p
  220. wait(0.03)
  221. local function make(part)
  222. local gr = part.Parent:findFirstChild("Part")
  223. local porjectileposition = projectile.Position
  224. local portaldoor = Instance.new("Part", workspace)
  225. portaldoor.Size = Vector3.new(1, 1, 1)
  226. portaldoor.BrickColor = BrickColor.new("Electric blue")
  227. portaldoor.Anchored = true
  228. portaldoor.Shape = "Cylinder"
  229. portaldoor.Material = "Neon"
  230. portaldoor.CanCollide = false
  231. if blueexists == true then
  232. workspace.BluePortal:destroy()
  233. end
  234. blueexists = true
  235. portaldoor.Name = "BluePortal"
  236. portaldoor.CFrame = part.CFrame
  237. if part.Size.y < part.Size.x and part.Size.y < part.Size.z then --a big help from Toxsikkilla
  238. print("if y < x")
  239. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(0,0,math.pi / 2)
  240. elseif part.Size.x < part.Size.y and part.Size.x < part.Size.z then
  241. print("if x < y")
  242. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(math.pi / 2, 0, 0)
  243. elseif part.Size.z < part.Size.y and part.Size.z < part.Size.y then
  244. print("if z < y")
  245. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(0, math.pi / 2, 0)
  246. end
  247. portaldoor.Position = projectile.Position
  248. projectile:destroy()
  249. for i = 1,18 do
  250. portaldoor.Size = portaldoor.Size + Vector3.new(0,0.3,0.3)
  251. wait()
  252. end
  253. local function tp(part)
  254. local hum = part.Parent:findFirstChild("Humanoid")
  255. if hum ~= nil and blueexists and orangeexists and not tping then
  256. tping = true
  257. local tor = part.Parent:findFirstChild("Torso")
  258. if tor then
  259. local velocityoftorso = tor.Velocity
  260. local blport = workspace:findFirstChild("OrangePortal")
  261. if blport then
  262. tor.CFrame = workspace.OrangePortal.CFrame
  263. tor.Velocity = workspace.OrangePortal.CFrame.rightVector * -velocityoftorso * 1.7
  264. end
  265. end
  266. wait(0.3)
  267. tping = false
  268. end
  269. if not hum and blueexists and orangeexists and not tping then
  270. tping = true
  271. local cube = part.Parent:findFirstChild("Cube")
  272. if cube then
  273. tping = true
  274. local velocityoftorso = cube.Velocity
  275. cube.CFrame = workspace.OrangePortal.CFrame
  276. cube.Velocity = workspace.OrangePortal.CFrame.rightVector * -velocityoftorso * 1.7
  277. wait(0.3)
  278. tping = false
  279. end
  280. end
  281. wait(0.3)
  282. tping = false
  283. end
  284. portaldoor.Touched:connect(tp)
  285. end
  286. projectile.Touched:connect(make)
  287. end
  288. if orange then
  289. Shoot:Play()
  290. local projectile1 = Instance.new("Part", workspace)
  291. projectile1.Size = Vector3.new(1,1,1)
  292. projectile1.BrickColor = BrickColor.new("Deep orange")
  293. projectile1.Shape = "Ball"
  294. projectile1.CanCollide = true
  295. projectile1.Anchored = false
  296. projectile1.Material = "Neon"
  297. local vel1 = Instance.new("BodyVelocity", projectile1)
  298. vel1.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  299. vel1.Velocity = mouse.Hit.lookVector * 80
  300. projectile1.Position = gun.CFrame.p
  301. wait(0.03)
  302. local function make1(part)
  303. local gr = part.Parent:findFirstChild("Part")
  304. local portaldoor = Instance.new("Part", workspace)
  305. portaldoor.Size = Vector3.new(1, 1, 1)
  306. portaldoor.BrickColor = BrickColor.new("Deep orange")
  307. portaldoor.Anchored = true
  308. portaldoor.Material = "Neon"
  309. portaldoor.Shape = "Cylinder"
  310. portaldoor.CanCollide = false
  311. if orangeexists == true then
  312. workspace.OrangePortal:destroy()
  313. end
  314. portaldoor.CFrame = part.CFrame
  315. if part.Size.y < part.Size.x and part.Size.y < part.Size.z then --a big help from Toxsikkilla
  316. print("if y < x")
  317. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(0,0,math.pi / 2)
  318. elseif part.Size.x < part.Size.y and part.Size.x < part.Size.z then
  319. print("if x < y")
  320. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(math.pi / 2, 0, 0)
  321. elseif part.Size.z < part.Size.y and part.Size.z < part.Size.y then
  322. print("if z < y")
  323. portaldoor.CFrame = portaldoor.CFrame * CFrame.fromEulerAnglesXYZ(0, math.pi / 2, 0)
  324. end
  325. portaldoor.Position = projectile1.Position
  326. projectile1:destroy()
  327. for i = 1,18 do
  328. portaldoor.Size = portaldoor.Size + Vector3.new(0,0.3,0.3)
  329. wait()
  330. end
  331. orangeexists = true
  332. portaldoor.Name = "OrangePortal"
  333. local function tp(part)
  334. local hum = part.Parent:findFirstChild("Humanoid")
  335. if hum ~= nil and blueexists and orangeexists and not tping then
  336. tping = true
  337. local tor = part.Parent:findFirstChild("Torso")
  338. if tor then
  339. local velocityoftorso = tor.Velocity
  340. local blport = workspace:findFirstChild("BluePortal")
  341. if blport then
  342. tor.CFrame = workspace.BluePortal.CFrame
  343. tor.Velocity = workspace.BluePortal.CFrame.rightVector * -velocityoftorso * 1.7
  344. end
  345. end
  346. wait(0.3)
  347. tping = false
  348. end
  349. if not hum and blueexists and orangeexists and not tping then
  350. tping = true
  351. local cube = part.Parent:findFirstChild("Cube")
  352. if cube then
  353. tping = true
  354. local velocityoftorso = cube.Velocity
  355. local blport = workspace:findFirstChild("BluePortal")
  356. if velocityoftorso.y < velocityoftorso.z and velocityoftorso.y < velocityoftorso.x then
  357. cube.Velocity = -velocityoftorso * 1.5
  358. if blport then
  359. cube.CFrame = workspace.BluePortal.rightVector * -velocityoftorso * 1.7
  360. end
  361. end
  362. wait(0.3)
  363. tping = false
  364. end
  365. wait(0.3)
  366. tping = false
  367. end
  368. wait(0.3)
  369. tping = false
  370. end
  371. portaldoor.Touched:connect(tp)
  372. end
  373. projectile1.Touched:connect(make1)
  374. end
  375.  
  376. for i = 0,1 , 0.3 do
  377. wait()
  378. lhandweld.C0 = lhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,-0.2),i)
  379. rhandweld.C0 = rhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,0.2),i)
  380. end
  381. for i = 0,1 , 0.3 do
  382. wait()
  383. lhandweld.C0 = lhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,0.2),i)
  384. rhandweld.C0 = rhandweld.C0 * CFrame.new():lerp(CFrame.Angles(0,0,-0.2),i)
  385. end
  386. using = false
  387. end
  388. end
  389. function remove(key)
  390. key = key:lower()
  391. if key == "r" then
  392. if blueexists or orangeexists or blueexists and orangeexists then
  393. workspace.OrangePortal:destroy()
  394. workspace.BluePortal:destroy()
  395. orangeexists = false
  396. blueexists = false
  397. end
  398. end
  399. end
  400. cubesp = false
  401. function cubespawn(key)
  402. key = key:lower()
  403. if key == "c" then
  404. if cubesp then
  405. workspace.Cube:destroy()
  406. end
  407. cubesp = true
  408. local coobe = Instance.new("Part", workspace)
  409. coobe.Size = Vector3.new(2.774, 2.834, 2.804)
  410. coobe:BreakJoints()
  411. coobe.Position = game.Players.LocalPlayer.Character.Torso.Position
  412. coobe.Name = "Cube"
  413. local meh = Instance.new("SpecialMesh", coobe)
  414. meh.MeshId = "rbxassetid://464957313"
  415. meh.TextureId = "rbxassetid://464957325"
  416. meh.Scale = Vector3.new(0.8,0.8,0.8)
  417. local function sounds()
  418. if not impacting then
  419. impacting = true
  420. local impactspeed = math.random(0.9,1.1)
  421. impact.PlaybackSpeed = impactspeed
  422. wait(0.2)
  423. impacting = false
  424. end
  425. end
  426. coobe.Touched:connect(sounds)
  427. end
  428. end
  429. function deleterportalsondedth()
  430. if orangeexists or blueexists or blueexists and orangeexists then
  431. workspace.OrangePortal:destroy()
  432. workspace.BluePortal:destroy()
  433. if cubesp then
  434. workspace.Cube:destroy()
  435. end
  436. end
  437. end
  438. game.Players.LocalPlayer.Character.Humanoid.Died:connect(deleterportalsondedth)
  439. mouse.KeyDown:connect(cubespawn)
  440. mouse.Button1Down:connect(portal)
  441. mouse.KeyDown:connect(changeportals)
  442. mouse.KeyDown:connect(remove)
Add Comment
Please, Sign In to add comment