Namoo546

Self Defend

Jun 15th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.86 KB | None | 0 0
  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,game,owner = owner,game
  3. local RealPlayer = Player
  4. do
  5. print("FE Compatibility code V2 by Mokiros")
  6. local RealPlayer = RealPlayer
  7. script.Parent = RealPlayer.Character
  8.  
  9. --Fake event to make stuff like Mouse.KeyDown work
  10. local Disconnect_Function = function(this)
  11. this[1].Functions[this[2]] = nil
  12. end
  13. local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
  14. local FakeEvent_Metatable = {__index={
  15. Connect = function(this,f)
  16. local i = tostring(math.random(0,10000))
  17. while this.Functions[i] do
  18. i = tostring(math.random(0,10000))
  19. end
  20. this.Functions[i] = f
  21. return setmetatable({this,i},Disconnect_Metatable)
  22. end
  23. }}
  24. FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
  25. local function fakeEvent()
  26. return setmetatable({Functions={}},FakeEvent_Metatable)
  27. end
  28.  
  29. --Creating fake input objects with fake variables
  30. local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
  31. FakeMouse.keyUp = FakeMouse.KeyUp
  32. FakeMouse.keyDown = FakeMouse.KeyDown
  33. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  34. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  35. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  36. end}
  37. --Merged 2 functions into one by checking amount of arguments
  38. CAS.UnbindAction = CAS.BindAction
  39.  
  40. --This function will trigger the events that have been :Connect()'ed
  41. local function TriggerEvent(self,ev,...)
  42. for _,f in pairs(self[ev].Functions) do
  43. f(...)
  44. end
  45. end
  46. FakeMouse.TriggerEvent = TriggerEvent
  47. UIS.TriggerEvent = TriggerEvent
  48.  
  49. --Client communication
  50. local Event = Instance.new("RemoteEvent")
  51. Event.Name = "UserInput_Event"
  52. Event.OnServerEvent:Connect(function(plr,io)
  53. if plr~=RealPlayer then return end
  54. FakeMouse.Target = io.Target
  55. FakeMouse.Hit = io.Hit
  56. if not io.isMouse then
  57. local b = io.UserInputState == Enum.UserInputState.Begin
  58. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  59. return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
  60. end
  61. if io.UserInputType == Enum.UserInputType.MouseButton2 then
  62. return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
  63. end
  64. for _,t in pairs(CAS.Actions) do
  65. for _,k in pairs(t.Keys) do
  66. if k==io.KeyCode then
  67. t.Function(t.Name,io.UserInputState,io)
  68. end
  69. end
  70. end
  71. FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  72. UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
  73. end
  74. end)
  75. Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
  76. local Mouse = owner:GetMouse()
  77. local UIS = game:GetService("UserInputService")
  78. local input = function(io,RobloxHandled)
  79. if RobloxHandled then return end
  80. --Since InputObject is a client-side instance, we create and pass table instead
  81. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
  82. end
  83. UIS.InputBegan:Connect(input)
  84. UIS.InputEnded:Connect(input)
  85.  
  86. local h,t
  87. --Give the server mouse data every second frame, but only if the values changed
  88. --If player is not moving their mouse, client won't fire events
  89. local HB = game:GetService("RunService").Heartbeat
  90. while true do
  91. if h~=Mouse.Hit or t~=Mouse.Target then
  92. h,t=Mouse.Hit,Mouse.Target
  93. Event:FireServer({isMouse=true,Target=t,Hit=h})
  94. end
  95. --Wait 2 frames
  96. for i=1,2 do
  97. HB:Wait()
  98. end
  99. end]==],script)
  100.  
  101. ----Sandboxed game object that allows the usage of client-side methods and services
  102. --Real game object
  103. local RealGame = game
  104.  
  105. --Metatable for fake service
  106. local FakeService_Metatable = {
  107. __index = function(self,k)
  108. local s = rawget(self,"_RealService")
  109. if s then
  110. return typeof(s[k])=="function"
  111. and function(_,...)return s[k](s,...)end or s[k]
  112. end
  113. end,
  114. __newindex = function(self,k,v)
  115. local s = rawget(self,"_RealService")
  116. if s then s[k]=v end
  117. end
  118. }
  119. local function FakeService(t,RealService)
  120. t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService
  121. return setmetatable(t,FakeService_Metatable)
  122. end
  123.  
  124. --Fake game object
  125. local FakeGame = {
  126. GetService = function(self,s)
  127. return rawget(self,s) or RealGame:GetService(s)
  128. end,
  129. Players = FakeService({
  130. LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
  131. },"Players"),
  132. UserInputService = FakeService(UIS,"UserInputService"),
  133. ContextActionService = FakeService(CAS,"ContextActionService"),
  134. RunService = FakeService({
  135. _btrs = {},
  136. RenderStepped = RealGame:GetService("RunService").Heartbeat,
  137. BindToRenderStep = function(self,name,_,fun)
  138. self._btrs[name] = self.Heartbeat:Connect(fun)
  139. end,
  140. UnbindFromRenderStep = function(self,name)
  141. self._btrs[name]:Disconnect()
  142. end,
  143. },"RunService")
  144. }
  145. rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer)
  146. FakeGame.service = FakeGame.GetService
  147. FakeService(FakeGame,game)
  148. --Changing owner to fake player object to support owner:GetMouse()
  149. game,owner = FakeGame,FakeGame.Players.LocalPlayer
  150. end
  151. lp=game:service'Players'.LocalPlayer
  152. pl=lp.Character
  153. e=0
  154. ring={}
  155.  
  156. Part = function(x,y,z,color,tr,cc,an,parent)
  157. local p = Instance.new('Part',parent or Weapon)
  158. p.formFactor = 'Custom'
  159. p.Size = Vector3.new(x,y,z)
  160. p.BrickColor = BrickColor.new(color)
  161. p.CanCollide = cc
  162. p.Transparency = tr
  163. p.Anchored = an
  164. p.TopSurface,p.BottomSurface = 0,0
  165. p.Material="Neon"
  166. return p
  167. end
  168.  
  169. Weld = function(p0,p1,x,y,z,rx,ry,rz,par)
  170. p0.Position = p1.Position
  171. local w = Instance.new('Motor',par or p0)
  172. w.Part0 = p0
  173. w.Part1 = p1
  174. w.C1 = CFrame.new(x,y,z)*CFrame.Angles(rx,ry,rz)
  175. return w
  176. end
  177.  
  178. so = function(id,par,lo,pi,tm)
  179. local s = Instance.new("Sound",par)
  180. s.Looped=lo
  181. s.Pitch=pi
  182. s.SoundId = "http://roblox.com/asset/?id="..id
  183. s:play()
  184. s.Volume=1
  185. Spawn(function()
  186. wait(tm)
  187. s:Stop''
  188. s:Destroy''
  189. end)
  190. return s
  191. end
  192. findHumanoid = function(where)
  193. if where and where:IsA("Model") then
  194. for i,v in pairs(where:GetChildren()) do
  195. if v:IsA("Humanoid") then return v end
  196. end
  197. end
  198. end
  199.  
  200. Mesh = function(par,num,x,y,z)
  201. local msh = _
  202. if num == 1 then
  203. msh = Instance.new("CylinderMesh",par)
  204. elseif num == 2 then
  205. msh = Instance.new("SpecialMesh",par)
  206. msh.MeshType = 3
  207. elseif num == 3 then
  208. msh = Instance.new("BlockMesh",par)
  209. elseif num == 4 then
  210. msh = Instance.new("SpecialMesh",par)
  211. msh.MeshType = "Torso"
  212. elseif type(num) == 'string' then
  213. msh = Instance.new("SpecialMesh",par)
  214. msh.MeshId = num
  215. end
  216. msh.Scale = Vector3.new(x,y,z)
  217. return msh
  218. end
  219.  
  220. Lightning = function(Start,End,Times,Offset,Color,Thickness)
  221. local magz = (Start - End).magnitude local curpos = Start local trz = {-Offset,Offset}
  222. for i=1,Times do
  223. local li = Instance.new("Part",workspace) li.TopSurface =0 li.BottomSurface = 0 li.Anchored = true li.Transparency = 0 li.BrickColor = Color li.Material="Neon"
  224. li.formFactor = "Custom" li.CanCollide = false li.Size = Vector3.new(Thickness,Thickness,magz/Times) local ofz = Vector3.new(trz[math.random(1,2)],trz[math.random(1,2)],trz[math.random(1,2)])
  225. local trolpos = CFrame.new(curpos,End)*CFrame.new(0,0,magz/Times).p+ofz
  226. if Times == i then
  227. local magz2 = (curpos - End).magnitude li.Size = Vector3.new(Thickness,Thickness,magz2)
  228. li.CFrame = CFrame.new(curpos,End)*CFrame.new(0,0,-magz2/2)
  229. else
  230. li.CFrame = CFrame.new(curpos,trolpos)*CFrame.new(0,0,magz/Times/2)
  231. end
  232. curpos = li.CFrame*CFrame.new(0,0,magz/Times/2).p Spawn(function() for i=1,10 do wait() li.Transparency = li.Transparency+.1 end li:Destroy() end)
  233. end
  234. end
  235.  
  236. function skul(v)
  237. if v:findFirstChild("Torso") ~= nil then
  238. for i=1,30 do
  239. local prt= Part(1,.2,1,'Black',0,true,false,workspace)
  240. prt.Material='Concrete'
  241. prt.CanCollide=false
  242. prt.CFrame=v.Torso.CFrame*CFrame.new(math.random(-30,30)/10,math.random(-20,30)/10,math.random(-20,20)/10)
  243. game.Debris:AddItem(prt,math.random(50,70)/10)
  244. end
  245. ypcall(function()v.Head.face:Destroy()end)
  246. local ms= Mesh(v.Head,'http://www.roblox.com/asset/?id=4770583',3.2,3.2,3.2)
  247. ms.TextureId='http://www.roblox.com/asset/?id=4770560'
  248. local ded=so('16433289',v.Head,false,1,1)
  249. for _,a in pairs(v:GetChildren()) do if a.Name ~= 'Head' and not a:IsA'Humanoid' then a:remove() end end
  250. end
  251. end
  252.  
  253. mod=Instance.new("Model",pl)
  254. mainp=Part(1,1,1,"",1,false,false,mod)
  255. mainw=Weld(mainp,pl['Torso'],0,0,0,0,0,0,mainp)
  256.  
  257. for i=1,360,24 do
  258. local p=Part(.1,.1,2.5,'',.9,false,false,mod)
  259. table.insert(ring,p)
  260. local w=Weld(p,mainp,0,0,0,0,0,0,p)
  261. w.C1=CFrame.new(0,0,0)*CFrame.Angles(math.rad(i),0,0)*CFrame.new(0,6,0);
  262. end
  263.  
  264. for i=1,360,24 do
  265. local p=Part(.1,.1,2.5,'',.9,false,false,mod)
  266. table.insert(ring,p)
  267. local w=Weld(p,mainp,0,0,0,0,0,0,p)
  268. w.C1=CFrame.new(0,0,0)*CFrame.Angles(0,math.rad(i),0)*CFrame.new(6,0,0);
  269. end
  270.  
  271. Spawn(function()
  272. while wait() do
  273. e=e+1
  274. for i,v in pairs(workspace:children()) do
  275. if v:IsA("Model") and findHumanoid(v) then
  276. if v:findFirstChild("Head") and v:findFirstChild("Torso") then
  277. if (v:findFirstChild("Torso").Position - pl.Torso.Position).magnitude < 7.5 and v.Name ~= pl.Name then
  278. Lightning(v.Torso.Position,pl['Torso'].Position,math.random(5,10),math.random(-2.5,2.5),BrickColor.random(),0.35)
  279. skul(v)
  280. Spawn(function()
  281. for i=1,10 do wait(.01)
  282. for o=1,#ring do
  283. ring[o].Transparency=i/10-.1
  284. end
  285. end
  286. end)
  287. end
  288. end
  289. end
  290. end
  291. mainw.C1=CFrame.new()*CFrame.Angles(math.rad(e),-math.rad(e),math.rad(e))
  292. end
  293. end)
Add Comment
Please, Sign In to add comment