Advertisement
HenloMyDude

posses anyone

Oct 10th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.73 KB | None | 0 0
  1. print("posses anyone!")
  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,game,owner = owner,game
  6. local RealPlayer = Player
  7. do
  8. print("FE Compatibility code V2 by Mokiros")
  9. local RealPlayer = RealPlayer
  10. script.Parent = RealPlayer.Character
  11.  
  12. --Fake event to make stuff like Mouse.KeyDown work
  13. local Disconnect_Function = function(this)
  14. this[1].Functions[this[2]] = nil
  15. end
  16. local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
  17. local FakeEvent_Metatable = {__index={
  18. Connect = function(this,f)
  19. local i = tostring(math.random(0,10000))
  20. while this.Functions[i] do
  21. i = tostring(math.random(0,10000))
  22. end
  23. this.Functions[i] = f
  24. return setmetatable({this,i},Disconnect_Metatable)
  25. end
  26. }}
  27. FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
  28. local function fakeEvent()
  29. return setmetatable({Functions={}},FakeEvent_Metatable)
  30. end
  31.  
  32. --Creating fake input objects with fake variables
  33. local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
  34. FakeMouse.keyUp = FakeMouse.KeyUp
  35. FakeMouse.keyDown = FakeMouse.KeyDown
  36. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  37. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  38. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  39. end}
  40. --Merged 2 functions into one by checking amount of arguments
  41. CAS.UnbindAction = CAS.BindAction
  42.  
  43. --This function will trigger the events that have been :Connect()'ed
  44. local function TriggerEvent(self,ev,...)
  45. for _,f in pairs(self[ev].Functions) do
  46. f(...)
  47. end
  48. end
  49. FakeMouse.TriggerEvent = TriggerEvent
  50. UIS.TriggerEvent = TriggerEvent
  51.  
  52. --Client communication
  53. local Event = Instance.new("RemoteEvent")
  54. Event.Name = "UserInput_Event"
  55. Event.OnServerEvent:Connect(function(plr,io)
  56. if plr~=RealPlayer then return end
  57. FakeMouse.Target = io.Target
  58. FakeMouse.Hit = io.Hit
  59. if not io.isMouse then
  60. local b = io.UserInputState == Enum.UserInputState.Begin
  61. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  62. return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
  63. end
  64. if io.UserInputType == Enum.UserInputType.MouseButton2 then
  65. return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
  66. end
  67. for _,t in pairs(CAS.Actions) do
  68. for _,k in pairs(t.Keys) do
  69. if k==io.KeyCode then
  70. t.Function(t.Name,io.UserInputState,io)
  71. end
  72. end
  73. end
  74. FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  75. UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
  76. end
  77. end)
  78. Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
  79. local Mouse = owner:GetMouse()
  80. local UIS = game:GetService("UserInputService")
  81. local input = function(io,RobloxHandled)
  82. if RobloxHandled then return end
  83. --Since InputObject is a client-side instance, we create and pass table instead
  84. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
  85. end
  86. UIS.InputBegan:Connect(input)
  87. UIS.InputEnded:Connect(input)
  88. local h,t
  89. --Give the server mouse data every second frame, but only if the values changed
  90. --If player is not moving their mouse, client won't fire events
  91. local HB = game:GetService("RunService").Heartbeat
  92. while true do
  93. if h~=Mouse.Hit or t~=Mouse.Target then
  94. h,t=Mouse.Hit,Mouse.Target
  95. Event:FireServer({isMouse=true,Target=t,Hit=h})
  96. end
  97. --Wait 2 frames
  98. for i=1,2 do
  99. HB:Wait()
  100. end
  101. end]==],script)
  102.  
  103. ----Sandboxed game object that allows the usage of client-side methods and services
  104. --Real game object
  105. local RealGame = game
  106.  
  107. --Metatable for fake service
  108. local FakeService_Metatable = {
  109. __index = function(self,k)
  110. local s = rawget(self,"_RealService")
  111. if s then
  112. return typeof(s[k])=="function"
  113. and function(_,...)return s[k](s,...)end or s[k]
  114. end
  115. end,
  116. __newindex = function(self,k,v)
  117. local s = rawget(self,"_RealService")
  118. if s then s[k]=v end
  119. end
  120. }
  121. local function FakeService(t,RealService)
  122. t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService
  123. return setmetatable(t,FakeService_Metatable)
  124. end
  125.  
  126. --Fake game object
  127. local FakeGame = {
  128. GetService = function(self,s)
  129. return rawget(self,s) or RealGame:GetService(s)
  130. end,
  131. Players = FakeService({
  132. LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
  133. },"Players"),
  134. UserInputService = FakeService(UIS,"UserInputService"),
  135. ContextActionService = FakeService(CAS,"ContextActionService"),
  136. RunService = FakeService({
  137. _btrs = {},
  138. RenderStepped = RealGame:GetService("RunService").Heartbeat,
  139. BindToRenderStep = function(self,name,_,fun)
  140. self._btrs[name] = self.Heartbeat:Connect(fun)
  141. end,
  142. UnbindFromRenderStep = function(self,name)
  143. self._btrs[name]:Disconnect()
  144. end,
  145. },"RunService")
  146. }
  147. rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer)
  148. FakeGame.service = FakeGame.GetService
  149. FakeService(FakeGame,game)
  150. --Changing owner to fake player object to support owner:GetMouse()
  151. game,owner = FakeGame,FakeGame.Players.LocalPlayer
  152. end
  153.  
  154. plr = owner
  155. char = plr.Character
  156. mouse = plr:GetMouse()
  157.  
  158. ezweld = function(p, a, b, cf)
  159. local weld = Instance.new("Weld",p)
  160. weld.Part0 = a
  161. weld.Part1 = b
  162. weld.C0 = cf
  163. return weld
  164. end
  165.  
  166. invis = function(chara)
  167. for _,v in pairs (chara:children()) do
  168. if v:IsA("Hat") or v:IsA("Accessory") then
  169. v:FindFirstChildOfClass("Part").Transparency = 1
  170. end
  171. if v:IsA("Part") or v:IsA("MeshPart") then
  172. v.Transparency = 1
  173. for _,v in pairs (v:children()) do
  174. if v:IsA("Decal") or v:IsA("Texture") then
  175. v.Transparency = 1
  176. end
  177. end
  178. end
  179. if v:IsA("Model") then
  180. for _,v in pairs (chara:children()) do
  181. if v:IsA("Hat") or v:IsA("Accessory") then
  182. v:FindFirstChildOfClass("Part").Transparency = 1
  183. end
  184. if v:IsA("Part") or v:IsA("MeshPart") and v.Name ~= "HumanoidRootPart" then
  185. v.Transparency = 1
  186. for _,v in pairs (v:children()) do
  187. if v:IsA("Decal") or v:IsA("Texture") then
  188. v.Transparency = 1
  189. end
  190. end
  191. end
  192. end
  193. end
  194. end
  195. end
  196.  
  197. uninvis = function(chara)
  198. for _,v in pairs (chara:children()) do
  199. if v:IsA("Hat") or v:IsA("Accessory") then
  200. v:FindFirstChildOfClass("Part").Transparency = 0
  201. end
  202. if v:IsA("Part") or v:IsA("MeshPart") and v.Name ~= "HumanoidRootPart" then
  203. v.Transparency = 0
  204. for _,v in pairs (v:children()) do
  205. if v:IsA("Decal") or v:IsA("Texture") then
  206. v.Transparency = 0
  207. end
  208. end
  209. if v.Name == "HumanoidRootPart" then
  210. v.Transparency = 1
  211. end
  212. end
  213. if v:IsA("Model") then
  214. for _,v in pairs (chara:children()) do
  215. if v:IsA("Hat") or v:IsA("Accessory") then
  216. v:FindFirstChildOfClass("Part").Transparency = 0
  217. end
  218. if v:IsA("Part") or v:IsA("MeshPart") and v.Name ~= "HumanoidRootPart" then
  219. v.Transparency = 0
  220. for _,v in pairs (v:children()) do
  221. if v:IsA("Decal") or v:IsA("Texture") then
  222. v.Transparency = 0
  223. end
  224. end
  225. end
  226. end
  227. end
  228. end
  229. end
  230.  
  231. function removeprops(chara)
  232. for _,v in pairs (chara:children()) do
  233. if v:IsA("Part") or v:IsA("MeshPart") then
  234. if v.Name == "prop" then
  235. v:Destroy()
  236. uninvis(chara)
  237. end
  238. end
  239. if v:IsA("MeshPart") then
  240. if v.Name == "prop" then
  241. v:Destroy()
  242. uninvis(chara)
  243. end
  244. end
  245. if v:IsA("UnionOperation") then
  246. if v.Name == "prop" then
  247. v:Destroy()
  248. uninvis(chara)
  249. end
  250. end
  251. if v:IsA("WedgePart") then
  252. if v.Name == "prop" then
  253. v:Destroy()
  254. uninvis(chara)
  255. end
  256. end
  257. if v:IsA("CornerWedgePart") then
  258. if v.Name == "prop" then
  259. v:Destroy()
  260. uninvis(chara)
  261. end
  262. end
  263. if v:IsA("TrussPart") then
  264. if v.Name == "prop" then
  265. v:Destroy()
  266. uninvis(chara)
  267. end
  268. end
  269. end
  270. end
  271.  
  272. function transform()
  273. if mouse.Target then
  274. removeprops(char)
  275. local part = mouse.Target
  276. invis(char)
  277. local newpart = part.Parent:FindFirstChild("HumanoidRootPart"):Clone()
  278. newpart.Name = "prop"
  279. newpart.Anchored = false
  280. newpart.Parent = char
  281. ezweld(char.Head, newpart, char.HumanoidRootPart, CFrame.new())
  282. end
  283. end
  284.  
  285. --[[
  286. mouse.Button1Down:connect(function()
  287. if mouse.Target then
  288. removeprops(char)
  289. local part = mouse.Target
  290. invis(char)
  291. local newpart = part:Clone()
  292. newpart.Name = "prop"
  293. newpart.Anchored = false
  294. newpart.Parent = char
  295. ezweld(char, newpart, char.HumanoidRootPart, CFrame.new())
  296. end
  297. end)
  298. ]]--
  299.  
  300. mouse.KeyDown:connect(function(key)
  301. key=key:lower()
  302. if key == "q" then
  303. transform()
  304. end
  305. if key == "e" then
  306. removeprops(char)
  307. uninvis(char)
  308. char.Head:FindFirstChildOfClass("Weld"):Destroy()
  309. end
  310. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement