Advertisement
waconline

telekinesis

Jan 28th, 2020
1,445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.70 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. inew=Instance.new
  153. v3=Vector3.new
  154. c3=Color3.new
  155. On=true
  156. Distance=20
  157. Minimum=5
  158. Maximum=10000000000000
  159. LightColor=c3(0/255,230/255,150/255)
  160. Light=inew('PointLight')
  161. Light.Color=LightColor
  162. XVec=v3(0,0,0)
  163. Target=nil
  164. Adorn=nil
  165. BP=inew("BodyPosition")
  166. BP.maxForce=v3(1000000, 1000000, 1000000)
  167. BP.P=1000000.000
  168. BP.D=100000.000
  169. BP.position=v3(0,50,0)
  170. Q=false
  171. E=false
  172. hit=nil
  173. FireSize=10
  174. FireColor=c3(255/255,255/255,255/255)
  175. FireHeat=10
  176. RunService=game:GetService('RunService')
  177. Player=game.Players.LocalPlayer
  178. Mouse=Player:GetMouse()
  179. coroutine.wrap(function()
  180. script.Parent=nil
  181. RunService.RenderStepped:connect(function()
  182. if On==false then
  183. Adorn=nil
  184. end
  185. hit=Mouse.Hit
  186. Unit=(hit.p-Player.Character.Head.Position).unit
  187. NewPos=Player.Character.Head.Position+(Unit*Distance)-XVec
  188. if BP==nil then
  189. BP=inew("BodyPosition")
  190. else
  191. BP.position=NewPos
  192. end
  193. if Adorn~=nil then
  194. BP.Parent=Adorn
  195. Light.Parent=Adorn
  196. else
  197. BP.Parent=nil
  198. Light.Parent=nil
  199. end
  200. if Mouse.Target~=nil then Target=Mouse.Target else Target=nil end
  201. if Q==true and E==false then
  202. if Distance-1<Minimum then
  203. Distance=Minimum
  204. elseif Distance-1>=Minimum then
  205. Distance=Distance-1
  206. end
  207. end
  208. if Q==false and E==true then
  209. if Distance+1>Maximum then
  210. Distance=Maximum
  211. elseif Distance+1<=Maximum then
  212. Distance=Distance+1
  213. end
  214. end
  215. if Distance<Minimum then
  216. Distance=Minimum
  217. end
  218. end)
  219. end)()
  220. Player.Chatted:connect(function(msg)
  221. if string.lower(string.sub(msg,1,5))=='make/' then
  222. for e=1,tonumber(string.sub(msg,6)) do
  223. local Col=Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255)
  224. local br=Instance.new('Part', workspace)
  225. br.Size=Vector3.new(math.random(2,8),math.random(2,8),math.random(2,8))
  226. br.Position=Player.Character.Head.Position+ Vector3.new(math.random(-tonumber(string.sub(msg,6)),tonumber(string.sub(msg,6))), math.random(-tonumber(string.sub(msg,6)),tonumber(string.sub(msg,6))),math.random(-tonumber(string.sub(msg,6)),tonumber(string.sub(msg,6))) )
  227. br.BrickColor=BrickColor.new(Col)
  228. end
  229. end
  230. end)
  231. Mouse.KeyDown:connect(function(key)
  232. if (key)=='q' then
  233. Q=true
  234. elseif (key)=='e' then
  235. E=true
  236. elseif (key)=='t' then
  237. if Adorn~=nil then
  238. BP.Parent=nil
  239. Adorn.Velocity=Adorn.Velocity+(((Adorn.Position+XVec)-Player.Character.Head.Position)).unit*200
  240. Adorn=nil
  241. end
  242. end
  243. end)
  244. Mouse.KeyUp:connect(function(key)
  245. if (key)=='q' then
  246. Q=false
  247. elseif (key)=='e' then
  248. E=false
  249. elseif key=='k' and Adorn~=nil then
  250. for i, v in pairs(Adorn.Parent:GetChildren()) do
  251. if v:IsA('Humanoid') then v.Health=0 end
  252. end
  253. elseif key=='b' and Adorn~=nil then
  254. Adorn:BreakJoints()
  255. elseif (key)=='r' and Adorn ~=nil then
  256. if Adorn.Parent:FindFirstChild('ThisIsAModel') and Adorn.Parent.Fire.Value==false then
  257. for i, var in pairs(Adorn.Parent:GetChildren()) do
  258. if var:IsA('BasePart') then
  259. fire=inew('Fire',var)
  260. fire.Color=FireColor
  261. fire.Name='Fire23445'
  262. fire.Size=FireSize
  263. fire.Heat=FireHeat
  264. end
  265. end
  266. Adorn.Parent.Fire.Value=true
  267. elseif Adorn.Parent:FindFirstChild('ThisIsAModel') and Adorn.Parent.Fire.Value==true then
  268. for i, var in pairs(Adorn.Parent:GetChildren()) do
  269. if var:IsA('BasePart') and var:FindFirstChild('Fire23445') then
  270. var.Fire23445:Destroy()
  271. end
  272. end
  273. Adorn.Parent.Fire.Value=false
  274. elseif not Adorn.Parent:FindFirstChild('ThisIsAModel') then
  275. if not Adorn:FindFirstChild('Fire23445') then
  276. fire=inew('Fire',Adorn)
  277. fire.Color=FireColor
  278. fire.Name='Fire23445'
  279. fire.Size=FireSize
  280. fire.Heat=FireHeat
  281. elseif Adorn:FindFirstChild('Fire23445') then
  282. Adorn.Fire23445:Destroy()
  283. end
  284. end
  285. elseif (key)=='z' and Adorn ~=nil then
  286. if Adorn.Parent:FindFirstChild('ThisIsAModel') then
  287. if Adorn.Parent.Ghost.Value==false then
  288. for i, v in pairs(Adorn.Parent:GetChildren()) do
  289. if v:IsA('BasePart') then
  290. if v.Transparency==0 then
  291. tick=inew('BoolValue',v)
  292. tick.Name='Trans'
  293. v.Transparency=0.5
  294. else
  295. v.Transparency=v.Transparency*2
  296. end
  297. end
  298. end
  299. Adorn.Parent.Ghost.Value=true
  300. elseif Adorn.Parent.Ghost.Value==true then
  301. for i, v in pairs(Adorn.Parent:GetChildren()) do
  302. if v:IsA('BasePart') then
  303. if v:FindFirstChild('Trans') then
  304. v.Transparency=0
  305. v.Trans:Destroy()
  306. else
  307. v.Transparency=v.Transparency/2
  308. end
  309. end
  310. end
  311. Adorn.Parent.Ghost.Value=false
  312. end
  313. elseif not Adorn.Parent:FindFirstChild('ThisIsAModel') then
  314. if Adorn:FindFirstChild('Trans') then
  315. Adorn.Transparency=Adorn.Transparency/2
  316. Adorn.Trans:Destroy()
  317. if Adorn:FindFirstChild('Trans2') then
  318. Adorn.Transparency=0
  319. Adorn.Trans2:Destroy()
  320. end
  321. elseif not Adorn:FindFirstChild('Trans') then
  322. inew('BoolValue',Adorn).Name='Trans'
  323. if Adorn.Transparency<=0 then
  324. inew('BoolValue',Adorn).Name='Trans2'
  325. Adorn.Transparency=0.5
  326. else Adorn.Transparency=Adorn.Transparency*2
  327. end
  328. end
  329. end
  330. end
  331. end)
  332. Mouse.Button1Down:connect(function()
  333. if Adorn==nil and BP.Parent==nil and Target~=nil and (hit.p-Player.Character.Head.Position).magnitude<=Maximum and Target:IsDescendantOf(workspace) then
  334. Distance=(Target.Position-Player.Character.Head.Position).magnitude
  335. XVec=(hit.p-Target.Position)
  336. if not Target.Parent:FindFirstChild('ThisIsAModel') then
  337. local rt=Target.Size
  338. Minimum=math.sqrt((rt.X^2+rt.Y^2+rt.Z^2))+.5
  339. else
  340. local rt=Target.Parent:GetModelSize()
  341. Minimum=math.sqrt((rt.X^2+rt.Y^2+rt.Z^2))+.5
  342. end
  343. Adorn=Target
  344. end
  345. end)
  346.  
  347. Mouse.Button1Up:connect(function()
  348. if Adorn~=nil then
  349. Adorn=nil
  350. BP.Parent=nil
  351. end
  352. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement