ProKameron528

lightning telekinesis testing for FE

Sep 13th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     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. local isScriptNil = false
  152.  
  153. local PlrName = "xExplicitCass"
  154. local Plrs = game:GetService("Players")
  155. local RunService = game:GetService("RunService")
  156. local Content = game:GetService("ContentProvider")
  157. local LP = Plrs.LocalPlayer
  158. local Char = LP.Character
  159. local PlrGui = LP.PlayerGui
  160. local Backpack = LP.Backpack
  161. local Mouse = LP:GetMouse()
  162.  
  163. local Camera = Workspace.CurrentCamera
  164. local LastCamCF = Camera.CoordinateFrame
  165. local AnimJoints = {}
  166. local Cons = {}
  167. local mDown = false
  168. local Multi = false
  169. local Grabbing = false
  170. local Current = {}
  171. local Alpha = 1
  172. local LightNum = 1
  173.  
  174. Current.Part = nil
  175. Current.BP = nil
  176. Current.BA = nil
  177. Current.Mass = nil
  178.  
  179. local LastPart = nil
  180.  
  181. local Head = Char["Head"]
  182. local Torso = Char["Torso"]
  183. local Humanoid = Char["Humanoid"]
  184. local LA = Char["Left Arm"]
  185. local RA = Char["Right Arm"]
  186. local LL = Char["Left Leg"]
  187. local RL = Char["Right Leg"]
  188.  
  189. local LS, RS;
  190.  
  191. local OrigLS = Torso["Left Shoulder"]
  192. local OrigRS = Torso["Right Shoulder"]
  193.  
  194. for _,v in pairs(Char:GetChildren()) do
  195.     if v.Name == ModID then
  196.         v:Destroy()
  197.     end
  198. end
  199.  
  200. for _,v in pairs(PlrGui:GetChildren()) do
  201.     if v.Name == "PadsGui" then
  202.         v:Destroy()
  203.     end
  204. end
  205.  
  206. local ModID = "Pads"
  207. local Objects = {}
  208. local Grav = 196.2
  209.  
  210. local sin=math.sin
  211. local cos=math.cos
  212. local max=math.max
  213. local min=math.min
  214. local atan2=math.atan2
  215. local random=math.random
  216. local tau = 2 * math.pi
  217.  
  218. local BodyObjects = {
  219.     ["BodyVelocity"] = true;
  220.     ["BodyAngularVelocity"] = true;
  221.     ["BodyForce"] = true;
  222.     ["BodyThrust"] = true;
  223.     ["BodyPosition"] = true;
  224.     ["RocketPropulsion"] = true;
  225. }
  226.  
  227. if LP.Name == PlrName and isScriptNil then
  228.     script.Parent = nil
  229. end
  230.  
  231. LP.CameraMode = "Classic"
  232.  
  233. local Assets = {
  234. }
  235.  
  236. local LS0, LS1 = OrigLS.C0, OrigLS.C1
  237. local RS0, RS1 = OrigRS.C0, OrigRS.C1
  238.  
  239. for i,v in pairs(Assets) do
  240.     local ID = tostring(Assets[i])
  241.     Assets[i] = "http://www.roblox.com/asset/?id=" .. ID
  242.     Content:Preload("http://www.roblox.com/asset/?id=" .. ID)
  243. end
  244.  
  245. function QuaternionFromCFrame(cf)
  246.     local mx, my, mz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cf:components();
  247.     local trace = m00 + m11 + m22 if trace > 0 then
  248.         local s = math.sqrt(1 + trace);
  249.         local recip = 0.5/s;
  250.         return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5;
  251.     else
  252.         local i = 0;
  253.         if m11 > m00 then
  254.             i = 1;
  255.         end;
  256.         if m22 > (i == 0 and m00 or m11) then
  257.             i = 2 end if i == 0 then
  258.             local s = math.sqrt(m00-m11-m22+1);
  259.             local recip = 0.5/s return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip;
  260.         elseif i == 1 then
  261.             local s = math.sqrt(m11-m22-m00+1);
  262.             local recip = 0.5/s;
  263.             return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip ;
  264.         elseif i == 2 then
  265.             local s = math.sqrt(m22-m00-m11+1);
  266.             local recip = 0.5/s;
  267.             return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip;
  268.         end;
  269.     end;
  270. end;
  271.  
  272. function QuaternionToCFrame(px, py, pz, x, y, z, w)
  273.     local xs, ys, zs = x + x, y + y, z + z;
  274.     local wx, wy, wz = w*xs, w*ys, w*zs;
  275.     local xx = x*xs;
  276.     local xy = x*ys;
  277.     local xz = x*zs;
  278.     local yy = y*ys;
  279.     local yz = y*zs;
  280.     local zz = z*zs;
  281.     return CFrame.new(px, py, pz,1-(yy+zz), xy - wz, xz + wy,xy + wz, 1-(xx+zz), yz - wx, xz - wy, yz + wx, 1-(xx+yy))
  282. end;
  283.  
  284. function QuaternionSlerp(a, b, t)
  285.     local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4];
  286.     local startInterp, finishInterp;
  287.     if cosTheta >= 0.0001 then
  288.         if (1 - cosTheta) > 0.0001 then
  289.             local theta = math.acos(cosTheta);
  290.             local invSinTheta = 1/math.sin(theta);
  291.             startInterp = math.sin((1-t)*theta)*invSinTheta;
  292.             finishInterp = math.sin(t*theta)*invSinTheta;
  293.         else
  294.             startInterp = 1-t finishInterp = t;
  295.         end;
  296.     else
  297.         if (1+cosTheta) > 0.0001 then
  298.             local theta = math.acos(-cosTheta);
  299.             local invSinTheta = 1/math.sin(theta);
  300.             startInterp = math.sin((t-1)*theta)*invSinTheta;
  301.             finishInterp = math.sin(t*theta)*invSinTheta;
  302.         else startInterp = t-1 finishInterp = t;
  303.         end;
  304.     end;
  305.     return a[1]*startInterp + b[1]*finishInterp, a[2]*startInterp + b[2]*finishInterp, a[3]*startInterp + b[3]*finishInterp, a[4]*startInterp + b[4]*finishInterp;
  306. end;
  307.  
  308. function CLerp(a,b,t)
  309.     local qa={QuaternionFromCFrame(a)};
  310.     local qb={QuaternionFromCFrame(b)};
  311.     local ax,ay,az=a.x,a.y,a.z;
  312.     local bx,by,bz=b.x,b.y,b.z;
  313.     local _t=1-t;
  314.     return QuaternionToCFrame(_t*ax+t*bx,_t*ay+t*by,_t*az+t*bz,QuaternionSlerp(qa, qb, t));
  315. end
  316.  
  317. function GetWeld(weld)
  318.     local obj
  319.     for i, v in pairs(AnimJoints) do
  320.         if v[1] == weld then
  321.             obj = v
  322.             break
  323.         end
  324.     end
  325.     if not obj then
  326.         obj = {weld,NV}
  327.         table.insert(AnimJoints,obj)
  328.     end
  329.     return weld.C0.p, obj[2]
  330. end
  331.  
  332. function SetWeld(weld, i, loops, origpos, origangle, nextpos, nextangle, override, overrideLower, smooth)
  333.     smooth = smooth or 1
  334.     local obj
  335.     for i, v in pairs(AnimJoints) do
  336.         if v[1] == weld then
  337.             obj = v
  338.             break
  339.         end
  340.     end
  341.     if not obj then
  342.         obj = {weld,NV}
  343.         table.insert(AnimJoints,obj)
  344.     end
  345.    
  346.     local perc = (smooth == 1 and math.sin((math.pi/2)/loops*i)) or i/loops
  347.    
  348.     local tox,toy,toz = 0,0,0
  349.     tox = math.abs(origangle.x - nextangle.x) *perc
  350.     toy = math.abs(origangle.y - nextangle.y) *perc
  351.     toz = math.abs(origangle.z - nextangle.z) *perc
  352.     tox = ((origangle.x > nextangle.x and -tox) or tox)
  353.     toy = ((origangle.y > nextangle.y and -toy) or toy)
  354.     toz = ((origangle.z > nextangle.z and -toz) or toz)
  355.    
  356.     local tox2,toy2,toz2 = 0,0,0
  357.     tox2 = math.abs(origpos.x - nextpos.x) *perc
  358.     toy2 = math.abs(origpos.y - nextpos.y) *perc
  359.     toz2 = math.abs(origpos.z - nextpos.z) *perc
  360.     tox2 = (origpos.x > nextpos.x and -tox2) or tox2
  361.     toy2 = (origpos.y > nextpos.y and -toy2) or toy2
  362.     toz2 = (origpos.z > nextpos.z and -toz2) or toz2
  363.    
  364.     obj[2] = Vector3.new(origangle.x + tox, origangle.y + toy, origangle.z + toz)
  365.     weld.C0 = CFrame.new(origpos.x + tox2,origpos.y + toy2,origpos.z + toz2) * CFrame.Angles(origangle.x + tox,origangle.y + toy,origangle.z + toz)
  366. end
  367.  
  368. function RotateCamera(x, y)
  369.     Camera.CoordinateFrame = CFrame.new(Camera.Focus.p) * (Camera.CoordinateFrame - Camera.CoordinateFrame.p) * CFrame.Angles(x, y, 0) * CFrame.new(0, 0, (Camera.CoordinateFrame.p - Camera.Focus.p).magnitude)
  370. end
  371.  
  372. function GetAngles(cf)
  373.     local lv = cf.lookVector
  374.     return -math.asin(lv.y), math.atan2(lv.x, -lv.z)
  375. end
  376.  
  377. local LastCamCF = Camera.CoordinateFrame
  378.  
  379. function Look()
  380.     if AlphaOn == true then
  381.         local x, y = GetAngles(LastCamCF:toObjectSpace(Camera.CoordinateFrame))
  382.         Camera.CoordinateFrame = LastCamCF
  383.         RotateCamera(x * -(Alpha), y * -(Alpha))
  384.         LastCamCF = Camera.CoordinateFrame
  385.     end
  386. end
  387.  
  388. function Cor(Func)
  389.     local Ok, Err = coroutine.resume(coroutine.create(Func))
  390.     if not Ok then
  391.         print(Err)
  392.     end
  393. end
  394.  
  395. function Cor2(Func)
  396.     local Ok, Err = ypcall(Func)
  397.     if not Ok then
  398.         print(Err)
  399.     end
  400. end
  401.  
  402. function MakePads()
  403.     -- 1 - VTelekinesis
  404.     P1 = Instance.new("Model")
  405.     P1.Name = ModID
  406.  
  407.     -- 2 - RBase
  408.     P2 = Instance.new("Part")
  409.     P2.CFrame = CFrame.new(Vector3.new(21.100008, 1.95000589, 11.899971)) * CFrame.Angles(-0, 0, -0)
  410.     P2.FormFactor = Enum.FormFactor.Custom
  411.     P2.Size = Vector3.new(0.799999952, 0.200000003, 0.800000012)
  412.     P2.Anchored = true
  413.     P2.BrickColor = BrickColor.new("White")
  414.     P2.Friction = 0.30000001192093
  415.     P2.Shape = Enum.PartType.Block
  416.     P2.Name = "RBase"
  417.     P2.Parent = P1
  418.     P2.Transparency = 1
  419.     -- 3 - Mesh
  420.     P3 = Instance.new("CylinderMesh")
  421.     P3.Scale = Vector3.new(1, 0.5, 1)
  422.     P3.Parent = P2
  423.  
  424.     -- 4 - LBase
  425.     P4 = Instance.new("Part")
  426.     P4.CFrame = CFrame.new(Vector3.new(18.100008, 1.95000589, 11.899971)) * CFrame.Angles(-0, 0, -0)
  427.     P4.FormFactor = Enum.FormFactor.Custom
  428.     P4.Size = Vector3.new(0.799999952, 0.200000003, 0.800000012)
  429.     P4.Anchored = true
  430.     P4.BrickColor = BrickColor.new("White")
  431.     P4.Friction = 0.30000001192093
  432.     P4.Shape = Enum.PartType.Block
  433.     P4.Name = "LBase"
  434.     P4.Parent = P1
  435.     P4.Transparency = 1
  436.     -- 5 - Mesh
  437.     P5 = Instance.new("CylinderMesh")
  438.     P5.Scale = Vector3.new(1, 0.5, 1)
  439.     P5.Parent = P4
  440.  
  441.     -- 7 - Mesh
  442.     P7 = Instance.new("CylinderMesh")
  443.     P7.Scale = Vector3.new(1, 0.5, 1)
  444.     P7.Parent = P6
  445.  
  446.    
  447.  
  448.     -- 9 - Mesh
  449.     P9 = Instance.new("CylinderMesh")
  450.     P9.Scale = Vector3.new(1, 0.5, 1)
  451.     P9.Parent = P8
  452.  
  453.    
  454.  
  455.     -- 11 - Mesh
  456.     P11 = Instance.new("CylinderMesh")
  457.     P11.Scale = Vector3.new(1, 0.5, 1)
  458.     P11.Parent = P10
  459.  
  460.    
  461.     -- 13 - Mesh
  462.     P13 = Instance.new("CylinderMesh")
  463.     P13.Scale = Vector3.new(1, 0.5, 1)
  464.     P13.Parent = P12
  465.  
  466.  
  467.     -- 15 - Mesh
  468.     P15 = Instance.new("CylinderMesh")
  469.     P15.Scale = Vector3.new(1, 0.5, 1)
  470.     P15.Parent = P14
  471.  
  472.     -- 17 - Mesh
  473.     P17 = Instance.new("CylinderMesh")
  474.     P17.Scale = Vector3.new(1, 0.5, 1)
  475.     P17.Parent = P16
  476.  
  477.     P1.Parent = LP.Character
  478.     P1:MakeJoints()
  479.     return P1
  480. end
  481.  
  482. weldModel = function(model, unanchor, rooty)
  483.     local parts = {}
  484.     local function recurse(object)
  485.         if object:IsA("BasePart") then
  486.             table.insert(parts, object)
  487.         end
  488.         for _,child in pairs(object:GetChildren()) do
  489.             recurse(child)
  490.         end
  491.     end
  492.     recurse(model)
  493.    
  494.     local rootPart = rooty or parts[1]
  495.     for _, part in pairs(parts) do
  496.         local cframe = rootPart.CFrame:toObjectSpace(part.CFrame)
  497.         local weld = Instance.new("Weld")
  498.         weld.Part0 = rootPart
  499.         weld.Part1 = part
  500.         weld.C0 = cframe
  501.         weld.Parent = rootPart
  502.     end
  503.    
  504.     if unanchor then
  505.         for _, part in pairs(parts) do
  506.             part.Anchored = false
  507.             part.CanCollide = false
  508.         end
  509.     end
  510. end
  511.  
  512. weldItem = function(rootPart, Item, TheC0, unanchor, ParentItem)
  513.     local cframe = TheC0 or rootPart.CFrame:toObjectSpace(Item.CFrame)
  514.     local weld = Instance.new("Weld")
  515.     weld.Name = "Weld"
  516.     weld.Part0 = rootPart
  517.     weld.Part1 = Item
  518.     weld.C0 = cframe
  519.     weld.Parent = ParentItem and Item or rootPart
  520.    
  521.     if unanchor then
  522.         Item.Anchored = false
  523.     end
  524.     return weld, cframe
  525. end
  526.  
  527. scaleModel = function(model, scale)
  528.     local parts = {}
  529.     local function recurse(object)
  530.         if object:IsA("BasePart") then
  531.             table.insert(parts, object)
  532.         end
  533.         for _,child in pairs(object:GetChildren()) do
  534.             recurse(child)
  535.         end
  536.     end
  537.     recurse(model)
  538.    
  539.     local top, bottom, left, right, back, front
  540.     for _, part in pairs(parts) do
  541.         if top == nil or top < part.Position.y then         top = part.Position.y end
  542.         if bottom == nil or bottom > part.Position.y then   bottom = part.Position.y end
  543.         if left == nil or left > part.Position.x then       left = part.Position.x end
  544.         if right == nil or right < part.Position.x then     right = part.Position.x end
  545.         if back == nil or back > part.Position.z then       back = part.Position.z end
  546.         if front == nil or front < part.Position.z then     front = part.Position.z end
  547.     end
  548.    
  549.     local middle = Vector3.new( left+right, top+bottom, back+front )/2
  550.     local minSize = Vector3.new(0.2, 0.2, 0.2)
  551.    
  552.     for _, part in pairs(parts) do
  553.         local foo = part.CFrame.p - middle
  554.         local rotation = part.CFrame - part.CFrame.p
  555.         local newSize = part.Size*scale
  556.         part.FormFactor = "Custom"
  557.         part.Size = newSize
  558.         part.CFrame = CFrame.new( middle + foo*scale ) * rotation
  559.        
  560.         if newSize.x < minSize.x or newSize.y < minSize.y or newSize.z < minSize.z then
  561.             local mesh
  562.             for _, child in pairs(part:GetChildren()) do
  563.                 if child:IsA("DataModelMesh") then
  564.                     mesh = child
  565.                     break
  566.                 end
  567.             end
  568.            
  569.             if mesh == nil then
  570.                 mesh = Instance.new("BlockMesh", part)
  571.             end
  572.            
  573.             local oScale = mesh.Scale
  574.             local newScale = newSize/minSize * oScale
  575.             if 0.2 < newSize.x then newScale = Vector3.new(1 * oScale.x, newScale.y, newScale.z) end
  576.             if 0.2 < newSize.y then newScale = Vector3.new(newScale.x, 1 * oScale.y, newScale.z) end
  577.             if 0.2 < newSize.z then newScale = Vector3.new(newScale.x, newScale.y, 1 * oScale.z) end
  578.            
  579.             mesh.Scale = newScale
  580.         end
  581.     end
  582. end
  583.  
  584. function getMass(Obj, Total)
  585.     local newTotal = Total
  586.     local returnTotal = 0
  587.    
  588.     if Obj:IsA("BasePart") then
  589.         newTotal = newTotal + Objects[Obj]
  590.     elseif BodyObjects[Obj.ClassName] then
  591.         Obj:Destroy()
  592.     end
  593.    
  594.     if Obj:GetChildren() and #Obj:GetChildren() > 0 then
  595.         for _,v in pairs(Obj:GetChildren()) do
  596.             returnTotal = returnTotal + getMass(v, newTotal)
  597.         end
  598.     else
  599.         returnTotal = newTotal
  600.     end
  601.    
  602.     return returnTotal
  603. end
  604.  
  605. function getTargFromCurrent()
  606.     local Current = Current.Part
  607.     if Current:IsA("BasePart") then
  608.         return Current
  609.     elseif Current:findFirstChild("Torso") then
  610.         return Current.Torso
  611.     else
  612.         for _,v in pairs(Current:GetChildren()) do
  613.             if v:IsA("BasePart") then
  614.                 return v
  615.             end
  616.         end
  617.     end
  618. end
  619.  
  620. function Fire(Part, Vec, Inv)
  621.     pcall(function()
  622.         Current.BP:Destroy()
  623.         Current.BP = nil
  624.     end)
  625.     pcall(function()
  626.         Current.BA:Destroy()
  627.         Current.BA = nil
  628.     end)
  629.     pcall(function()
  630.         if Inv then
  631.             Part.Velocity = -((Vec - Torso.Position).unit * Grav * 1.1)
  632.         else
  633.             Part.Velocity = ((Vec - Camera.CoordinateFrame.p).unit * Grav * 1.1)
  634.         end
  635.         Current.Mass = nil
  636.     end)
  637.     Reset()
  638. end
  639.  
  640. function Reset()
  641.     LS.Parent = nil
  642.     RS.Parent = nil
  643.    
  644.     OrigLS.Parent = Torso
  645.     OrigRS.Parent = Torso
  646.    
  647.     OrigLS.C0 = LS0
  648.     OrigRS.C0 = RS0
  649. end
  650.  
  651. function Start()
  652.     Cor(function()
  653.         repeat wait(1/30) until LP.Character and LP.Character.Parent == Workspace and LP.Character:findFirstChild("Torso")
  654.         Char = LP.Character
  655.         PlrGui = LP.PlayerGui
  656.         Backpack = LP.Backpack
  657.         Mouse = LP:GetMouse()
  658.        
  659.         for _,v in pairs(Cons) do
  660.             v:disconnect()
  661.         end
  662.         Cons = {}
  663.  
  664.         Camera = Workspace.CurrentCamera
  665.         LastCamCF = Camera.CoordinateFrame
  666.         AnimJoints = {}
  667.         mDown = false
  668.         Multi = false
  669.         Grabbing = false
  670.         Current = {}
  671.         Alpha = 1
  672.  
  673.         Head = Char["Head"]
  674.         Torso = Char["Torso"]
  675.         Humanoid = Char["Humanoid"]
  676.         LA = Char["Left Arm"]
  677.         RA = Char["Right Arm"]
  678.         LL = Char["Left Leg"]
  679.         RL = Char["Right Leg"]
  680.        
  681.         OrigLS = Torso["Left Shoulder"]
  682.         OrigRS = Torso["Right Shoulder"]
  683.  
  684.         for _,v in pairs(Char:GetChildren()) do
  685.             if v.Name == ModID then
  686.                 v:Destroy()
  687.             end
  688.         end
  689.  
  690.         for _,v in pairs(PlrGui:GetChildren()) do
  691.             if v.Name == "PadsGui" then
  692.                 v:Destroy()
  693.             end
  694.         end
  695.        
  696.         LS = Instance.new("Weld")
  697.         RS = Instance.new("Weld")
  698.  
  699.         LS.Name = OrigLS.Name
  700.         LS.Part0 = Torso
  701.         LS.Part1 = LA
  702.         LS.C0 = LS0
  703.         LS.C1 = CFrame.new(0, 0.5, 0,  1, 0, 0,  0, 0, 1,  0, -1, 0)
  704.  
  705.         RS.Name = OrigRS.Name
  706.         RS.Part0 = Torso
  707.         RS.Part1 = RA
  708.         RS.C0 = RS0
  709.         RS.C1 = CFrame.new(0, 0.5, 0,  1, 0, 0,  0, 0, 1,  0, -1, 0)
  710.  
  711.         local Pads = MakePads()
  712.         local LPad = Pads.LBase
  713.         local RPad = Pads.RBase
  714.  
  715.         weldModel(LPad, true, LPad)
  716.         weldModel(RPad, true, RPad)
  717.  
  718.         local GripWeldL = Instance.new("Weld")
  719.         GripWeldL.Name = "GripWeldL"
  720.         GripWeldL.Part0 = LA
  721.         GripWeldL.Part1 = LPad
  722.         GripWeldL.C0 = CFrame.new(0, -1.05, 0) * CFrame.Angles(0, math.rad(180), 0)
  723.         GripWeldL.Parent = LA
  724.  
  725.         local GripWeldR = Instance.new("Weld")
  726.         GripWeldR.Name = "GripWeldR"
  727.         GripWeldR.Part0 = RA
  728.         GripWeldR.Part1 = RPad
  729.         GripWeldR.C0 = CFrame.new(0, -1.05, 0) * CFrame.Angles(0, math.rad(180), 0)
  730.         GripWeldR.Parent = RA
  731.        
  732.         local isParts = false
  733.  
  734.         table.insert(Cons, Mouse.KeyDown:connect(function(Key)
  735.             Key = Key:lower()
  736.             if Key == "z" then
  737.                 --Stuff
  738.             elseif Key == "f" then
  739.                 local Current = Current.Part
  740.                 if Current and Current.Parent ~= nil and not Multi then
  741.                     Current:BreakJoints()
  742.                 end
  743.             elseif Key == "q" then
  744.                 if isParts then
  745.                     isParts = false
  746.                     for _,v in pairs(Workspace:GetChildren()) do
  747.                         if v.Name == "MyPartV" and v:IsA("BasePart") then
  748.                             v:Destroy()
  749.                         end
  750.                     end
  751.                 else
  752.                     isParts = true
  753.                     for i = 1, 50 do
  754.                         local Part = Instance.new("Part")
  755.                         Part.Color = Color3.new(math.random(), math.random(), math.random())
  756.                         Part.Transparency = 0
  757.                         Part.Size = Vector3.new(math.random(1, 3), math.random(1, 3), math.random(1, 3))
  758.                         Part.Archivable = true
  759.                         Part.CanCollide = false
  760.                         Part.Material = "Neon"
  761.                         Part.Locked = false
  762.                         Part.CFrame = Torso.CFrame * CFrame.new(math.random(-15, 15), -1, math.random(-15, 15))
  763.                         Part.Anchored = true
  764.                         Part.Name = "MyPartV"
  765.                         Part.TopSurface = "Smooth"
  766.                         Part.BottomSurface = "Smooth"
  767.                         Part.Parent = Workspace
  768.                     end
  769.                 end
  770.             elseif Key == "e" then
  771.                 local Targ;
  772.                 if Current.Part and Current.Part ~= nil then
  773.                     Targ = getTargFromCurrent()
  774.                 else
  775.                     Targ = LastPart
  776.                 end
  777.                 if Targ and Targ.Parent ~= nil and not Multi then
  778.                     local Ex = Instance.new("Explosion", Workspace)
  779.                     Ex.Position = Targ.CFrame.p
  780.                     Ex.BlastRadius = 16
  781.                     Ex.DestroyJointRadiusPercent = 0.5
  782.                 end
  783.             elseif Key == "c" then
  784.                 if Current.Part and Current.Part.Parent ~= nil and not Multi then
  785.                     local Part = getTargFromCurrent()
  786.                     if Part then
  787.                         Grabbing = false
  788.                         if Mouse.Hit then
  789.                             local TargPos = CFrame.new(Camera.CoordinateFrame.p, Mouse.Hit.p) * CFrame.new(0, 0, -1000)
  790.                             Fire(Part, TargPos.p)
  791.                         else
  792.                             Fire(Part, Mouse.Origin.p + Mouse.UnitRay.Direction, true)
  793.                         end
  794.                     end
  795.                 end
  796.             end
  797.         end))
  798.  
  799.         table.insert(Cons, Mouse.Button1Up:connect(function()
  800.             mDown = false
  801.             if Grabbing == true and Multi == false then
  802.                 Grabbing = false
  803.                 Reset()
  804.             end
  805.             if Current.Part ~= nil then
  806.                 LastPart = getTargFromCurrent()
  807.                 Current = {}
  808.             end
  809.         end))
  810.  
  811.         local function makeLightning(Par, Start, End, Width, Length, RandomScale, ArcScale, Num1)
  812.             local oldParts = {}
  813.             for _,v in pairs(Par:GetChildren()) do
  814.                 v.CFrame = CFrame.new(5e5, 5e5, 5e5)
  815.                 table.insert(oldParts, v)
  816.             end
  817.             local Distance = (Start-End).Magnitude
  818.             local ArcScale = ArcScale or 1
  819.             local RandomScale = RandomScale or 0
  820.             local Last = Start
  821.             local IterNum = 0
  822.  
  823.             while Par.Parent do
  824.                 IterNum = IterNum + 1
  825.                 local New = nil
  826.                 if (Last-End).Magnitude < Length then
  827.                     New = CFrame.new(End)
  828.                 else
  829.                     if (End-Last).Magnitude < Length*2 then
  830.                         RandomScale = RandomScale*0.5
  831.                         ArcScale = ArcScale*0.5
  832.                     end
  833.                     local Direct = CFrame.new(Last,End)
  834.                     New = Direct*CFrame.Angles(math.rad(math.random(-RandomScale/4,RandomScale*ArcScale)),math.rad(math.random(-RandomScale,RandomScale)),math.rad(math.random(-RandomScale,RandomScale)))
  835.                     New = New*CFrame.new(0,0,-Length)
  836.                 end
  837.                 local Trail = nil
  838.                 if oldParts[IterNum] then
  839.                     Trail = oldParts[IterNum]
  840.                     Trail.BrickColor = ((Num1 % 2 == 0) and BrickColor.new("White")) or BrickColor.new("Cyan")
  841.                     Trail.Size = Vector3.new(Width, (Last-New.p).Magnitude, Width)
  842.                     Trail.CFrame = CFrame.new(New.p, Last)*CFrame.Angles(math.rad(90),0,0)*CFrame.new(0, -(Last-New.p).Magnitude/2, 0)
  843.                     oldParts[IterNum] = nil
  844.                 else
  845.                     Trail = Instance.new("Part")
  846.                     Trail.Name = "Part"
  847.                     Trail.FormFactor = "Custom"
  848.                     Trail.BrickColor = ((Num1 % 2 == 0) and BrickColor.new("White")) or BrickColor.new("White")
  849.                     Trail.Transparency = 0
  850.                     Trail.Anchored = true
  851.                     Trail.CanCollide = false
  852.                     Trail.Locked = true
  853.                     Trail.BackSurface = "SmoothNoOutlines"
  854.                     Trail.BottomSurface = "SmoothNoOutlines"
  855.                     Trail.FrontSurface = "SmoothNoOutlines"
  856.                     Trail.LeftSurface = "SmoothNoOutlines"
  857.                     Trail.RightSurface = "SmoothNoOutlines"
  858.                     Trail.TopSurface = "SmoothNoOutlines"
  859.                     Trail.Material = "Neon"
  860.                     Trail.Size = Vector3.new(Width, (Last-New.p).Magnitude, Width)
  861.                     Trail.CFrame = CFrame.new(New.p, Last)*CFrame.Angles(math.rad(90),0,0)*CFrame.new(0, -(Last-New.p).Magnitude/2, 0)
  862.                     Trail.Parent = Par
  863.                 end
  864.                 Last = New.p
  865.                 if (Last-End).Magnitude < 1 then
  866.                     break
  867.                 end
  868.             end
  869.             for _,v in pairs(oldParts) do
  870.                 v:Destroy()
  871.             end
  872.         end
  873.  
  874.         table.insert(Cons, Mouse.Button1Down:connect(function()
  875.             mDown = true
  876.             local Targ = Mouse.Target
  877.             Cor(function()
  878.                 if Targ and Objects[Targ] and not Multi then
  879.                     Grabbing = true
  880.                     Current.Part = Targ
  881.                     local Mass = Objects[Targ]
  882.                     local ForceNum = 0
  883.                     local Hum = nil
  884.                    
  885.                     for _,v in pairs(Targ:GetChildren()) do
  886.                         if BodyObjects[v.ClassName] then
  887.                             v:Destroy()
  888.                         end
  889.                     end
  890.                    
  891.                     for _,v in pairs(Workspace:GetChildren()) do
  892.                         if v:findFirstChild("Humanoid") and v:IsAncestorOf(Targ) then
  893.                             Hum = v.Humanoid
  894.                             Mass = getMass(v, 0)
  895.                             Current.Part = v
  896.                             break
  897.                         end
  898.                     end
  899.                    
  900.                     Current.Mass = Mass
  901.                    
  902.                     if not Hum then
  903.                         Targ:BreakJoints()
  904.                     end
  905.                    
  906.                     ForceNum = Mass * Grav
  907.                     Targ.CanCollide = true
  908.                     Targ.Anchored = false
  909.                    
  910.                     local BP = Instance.new("BodyPosition")
  911.                     BP.maxForce = Vector3.new(3 * ForceNum, 3 * ForceNum, 3 * ForceNum)
  912.                     BP.Parent = Targ
  913.                    
  914.                     local Ang = Instance.new("BodyAngularVelocity")
  915.                     Ang.Parent = Targ
  916.                    
  917.                     Current.BP = BP
  918.                     Current.BA = Ang
  919.                    
  920.                     OrigLS.Parent = nil
  921.                     OrigRS.Parent = nil
  922.                    
  923.                     LS.Parent = Torso
  924.                     RS.Parent = Torso
  925.                    
  926.                     LS.C0 = LS0
  927.                     RS.C0 = RS0
  928.                    
  929.                     local DirDot = Mouse.UnitRay.Direction:Dot(Targ.Position - Mouse.Origin.p)
  930.                     local BPPos = Vector3.new(0, 0, 0)
  931.                     local Vel = Vector3.new(0, 0, 0)
  932.                     local Vlev = random() * math.pi
  933.                     local RPos = Vector3.new(random() * 2 - 1, cos(Vlev), random() * 2 - 1)
  934.                    
  935.                     local Ball = Instance.new("Part")
  936.                     Ball.Name = "Ball"
  937.                     Ball.FormFactor = "Custom"
  938.                     Ball.Color = Color3.new(0, 1, 1)
  939.                     Ball.Transparency = 0.3
  940.                     Ball.Anchored = true
  941.                     Ball.CanCollide = false
  942.                     Ball.Locked = true
  943.                     Ball.BottomSurface, Ball.TopSurface = "Smooth", "Smooth"
  944.                     Ball.Size = Vector3.new(0.5, 0.5, 0.5)
  945.                     Ball.CFrame = Torso.CFrame * CFrame.new(0, 1, -3)
  946.                     Ball.Parent = Char
  947.  
  948.                     if Targ.Name == "MyPartV" then
  949.                         Targ.Name = "MyPartF"
  950.                     end
  951.  
  952.                     local LightMod = Instance.new("Model", Char)
  953.                        
  954.                     local Mesh = Instance.new("SpecialMesh")
  955.                     Mesh.MeshType = "Sphere"
  956.                     Mesh.Parent = Ball
  957.                    
  958.                     local Size = 0.5
  959.                     local Rise = true
  960.                    
  961.                     while Grabbing and BP and Ang and Targ.Parent ~= nil do
  962.                         local BPPos = Mouse.Origin.p + Mouse.UnitRay.Direction * DirDot
  963.                         Ang.angularvelocity = Vel
  964.                         BP.position = BPPos + RPos
  965.                         RPos = Vector3.new(max(-1, min(RPos.x + random() * 0.02 - 0.01, 1)), cos(Vlev), max(-1, min(RPos.z + random() * 0.02 - 0.01, 1)))
  966.                         Vel = Vector3.new(max(-1, min(Vel.x + random() * 0.2 - 0.1, 1)), max(-1, min(Vel.y + random() * 0.2 - 0.1, 1)), max(-1, min(Vel.z + random() * 0.2 - 0.1, 1)))
  967.                         Vlev = (Vlev + 0.05) % tau
  968.                        
  969.                         if Hum then
  970.                             Hum.Sit = true
  971.                         end
  972.                        
  973.                         if LA.Parent ~= nil and RA.Parent ~= nil then
  974.                             local LPos = (LA.CFrame * CFrame.new(0, -1, 0)).p
  975.                             local RPos = (RA.CFrame * CFrame.new(0, -1, 0)).p
  976.                             if Rise == true then
  977.                                 if Size < 0.6 then
  978.                                     Size = Size + 0.05
  979.                                 else
  980.                                     Size = Size + 0.1
  981.                                 end
  982.                                 if Size >= 2.2 then
  983.                                     Rise = false
  984.                                 end
  985.                             else
  986.                                 if Size > 2.1 then
  987.                                     Size = Size - 0.05
  988.                                 else
  989.                                     Size = Size - 0.1
  990.                                 end
  991.                                 if Size <= 0.5 then
  992.                                     Rise = true
  993.                                 end
  994.                             end
  995.                             Ball.Size = Vector3.new(Size, Size, Size)
  996.                             Ball.CFrame = CFrame.new(LPos:Lerp(RPos, 0.5), Targ.Position) * CFrame.new(0, 0, -2.2)
  997.                             LightNum = LightNum + 1
  998.                             makeLightning(LightMod, Ball.Position, Targ.Position, 0.2, 4, 50, 1, LightNum)
  999.                         elseif Ball.Parent ~= nil then
  1000.                             Ball:Destroy()
  1001.                         end
  1002.                        
  1003.                         if LS and LS.Parent == Torso then
  1004.                             LS.C0 = CFrame.new(Vector3.new(-1.5, 0.5, 0), Torso.CFrame:pointToObjectSpace((Targ.CFrame or Torso.CFrame * CFrame.new(-1.5, 0.5, 1)).p))
  1005.                         end
  1006.                         if RS and RS.Parent == Torso then
  1007.                             RS.C0 = CFrame.new(Vector3.new(1.5, 0.5, 0), Torso.CFrame:pointToObjectSpace((Targ.CFrame or Torso.CFrame * CFrame.new(1.5, 0.5, 1)).p))
  1008.                         end
  1009.                         RunService.Heartbeat:wait()
  1010.                     end
  1011.  
  1012.                     coroutine.resume(coroutine.create(function()
  1013.                         for i = 0.5, 1, 0.1 do
  1014.                             for i2,v in pairs(LightMod:GetChildren()) do
  1015.                                 --v.Light.Range = 6-(i*5)
  1016.                                 v.Transparency = i
  1017.                             end
  1018.                             wait(1/30)
  1019.                         end
  1020.                         LightMod:Destroy()
  1021.                     end))
  1022.                    
  1023.                     if BP and BP.Parent ~= nil then
  1024.                         BP:Destroy()
  1025.                     end
  1026.                    
  1027.                     if Ang and Ang.Parent ~= nil then
  1028.                         Ang:Destroy()
  1029.                     end
  1030.                    
  1031.                     pcall(function() Ball:Destroy() end)
  1032.                 end
  1033.             end)
  1034.         end))
  1035.     end)
  1036. end
  1037.  
  1038. function Add(Obj)
  1039.     if Obj:IsA("BasePart") and not Objects[Obj] and not (Obj.Name == "Base" and Obj.ClassName == "Part") then
  1040.         Objects[Obj] = Obj:GetMass()
  1041.         Obj.Changed:connect(function(P)
  1042.             if P:lower() == "size" and Objects[Obj] and Obj.Parent ~= nil then
  1043.                 Objects[Obj] = Obj:GetMass()
  1044.             end
  1045.         end)
  1046.     end
  1047. end
  1048.  
  1049. function Rem(Obj)
  1050.     if Objects[Obj] then
  1051.         Objects[Obj] = nil
  1052.     end
  1053. end
  1054.  
  1055. function Recursion(Obj)
  1056.     ypcall(function()
  1057.         Add(Obj)
  1058.         if #Obj:GetChildren() > 0 then
  1059.             for _,v in pairs(Obj:GetChildren()) do
  1060.                 Recursion(v)
  1061.             end
  1062.         end
  1063.     end)
  1064. end
  1065.  
  1066. Workspace.DescendantAdded:connect(function(Obj)
  1067.     Add(Obj)
  1068. end)
  1069.  
  1070. Workspace.DescendantRemoving:connect(function(Obj)
  1071.     Rem(Obj)
  1072. end)
  1073.  
  1074. for _,v in pairs(Workspace:GetChildren()) do
  1075.     Recursion(v)
  1076. end
  1077.  
  1078. Start()
  1079.  
  1080. if LP.Name == PlrName then
  1081.     LP.CharacterAdded:connect(Start)
  1082. end
  1083.  
  1084. local verlet = {}
  1085. verlet.step_time = 1 / 50
  1086. verlet.gravity = Vector3.new(0, -10, 0)
  1087.  
  1088. local char = game.Players.LocalPlayer.Character
  1089. local torso = char:WaitForChild("Torso")
  1090. local parts = {}
  1091. local render = game:GetService("RunService").RenderStepped
  1092.  
  1093. wait(2)
  1094.  
  1095. local point = {}
  1096. local link = {}
  1097. local rope = {}
  1098.  
  1099. local function ccw(A,B,C)
  1100.     return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x)
  1101. end
  1102.  
  1103. local function intersect(A,B,C,D)
  1104.     return ccw(A,C,D) ~= ccw(B,C,D) and ccw(A,B,C) ~= ccw(A,B,D)
  1105. end
  1106.  
  1107. local function vec2(v)
  1108.     return Vector2.new(v.x, v.z)
  1109. end
  1110.  
  1111. function point:step()
  1112.     if not self.fixed then
  1113.         local derivative = (self.position - self.last_position) * 0.95
  1114.         self.last_position = self.position
  1115.         self.position = self.position + derivative + (self.velocity * verlet.step_time ^ 2)
  1116.         --[[local torsoP = torso.CFrame * CFrame.new(-1, 0, 0.5)
  1117.         local torsoE = torso.CFrame * CFrame.new(1, 0, 0.5)
  1118.         local pointE = self.position + torso.CFrame.lookVector * 100
  1119.         local doIntersect = intersect(vec2(torsoP.p), vec2(torsoE.p), vec2(self.position), vec2(pointE))
  1120.         if not doIntersect then
  1121.             self.postition = self.position - torso.CFrame.lookVector * 10
  1122.         end]]
  1123.     end
  1124. end
  1125.  
  1126. function link:step()
  1127.     for i = 1, 1 do
  1128.         local distance = self.point1.position - self.point2.position
  1129.         local magnitude = distance.magnitude
  1130.         local differance = (self.length - magnitude) / magnitude
  1131.         local translation = ((self.point1.fixed or self.point2.fixed) and 1 or 0.6) * distance * differance
  1132.         if not self.point1.fixed then
  1133.             self.point1.position = self.point1.position + translation
  1134.         end
  1135.         if not self.point2.fixed then
  1136.             self.point2.position = self.point2.position - translation
  1137.         end
  1138.     end
  1139. end
  1140.  
  1141. function verlet.new(class, a, b, c)
  1142.     if class == "Point" then
  1143.         local new = {}
  1144.         setmetatable(new, {__index = point})
  1145.         new.class = class
  1146.         new.position = a or Vector3.new()
  1147.         new.last_position = new.position
  1148.         new.velocity = verlet.gravity
  1149.         new.fixed = false
  1150.         return new
  1151.     elseif class == "Link" then
  1152.         local new = {}
  1153.         setmetatable(new, {__index = link})
  1154.         new.class = class
  1155.         new.point1 = a
  1156.         new.point2 = b
  1157.         new.length = c or (a.position - b.position).magnitude
  1158.         return new
  1159.     elseif class == "Rope" then
  1160.         local new = {}
  1161.         setmetatable(new, {__index = link})
  1162.         new.class = class
  1163.         new.start_point = a
  1164.         new.finish_point = b
  1165.         new.points = {}
  1166.         new.links = {}
  1167.         local inc = (b - a) / 10
  1168.         for i = 0, 10 do
  1169.             table.insert(new.points, verlet.new("Point", a + (i * inc)))
  1170.         end
  1171.         for i = 2, #new.points do
  1172.             table.insert(new.links, verlet.new("Link", new.points[i - 1], new.points[i]))
  1173.         end
  1174.         return new
  1175.     end
  1176. end
  1177.  
  1178. local tris = {}
  1179. local triParts = {}
  1180.  
  1181. local function GetDiscoColor(hue)
  1182.  local section = hue % 1 * 3
  1183.  local secondary = 0.5 * math.pi * (section % 1)
  1184.  if section < 1 then
  1185.   return Color3.new(0, 0, 0)
  1186.  elseif section < 2 then
  1187.   return Color3.new(0, 0, 0)
  1188.  else
  1189.   return Color3.new(0, 0, 0)
  1190.  end
  1191. end
  1192.  
  1193. local function setupPart(part)
  1194.     part.Anchored = true
  1195.     part.FormFactor = 3
  1196.     part.CanCollide = false
  1197.     part.TopSurface = 10
  1198.     part.BottomSurface = 10
  1199.     part.LeftSurface = 10
  1200.     part.RightSurface = 10
  1201.     part.FrontSurface = 10
  1202.     part.BackSurface = 10
  1203.     part.Material = "Neon"
  1204.     local m = Instance.new("SpecialMesh", part)
  1205.     m.MeshType = "Wedge"
  1206.     m.Scale = Vector3.new(0.2, 1, 1)
  1207.     return part
  1208. end
  1209.  
  1210. local function CFrameFromTopBack(at, top, back)
  1211.     local right = top:Cross(back)
  1212.     return CFrame.new(at.x, at.y, at.z, right.x, top.x, back.x,  right.y, top.y, back.y, right.z, top.z, back.z)
  1213. end
  1214.  
  1215. local function drawTri(parent, a, b, c)
  1216.     local this = {}
  1217.     local mPart1 = table.remove(triParts, 1) or setupPart(Instance.new("Part"))
  1218.     local mPart2 = table.remove(triParts, 1) or setupPart(Instance.new("Part"))
  1219.     function this:Set(a, b, c)
  1220.         local ab, bc, ca = b-a, c-b, a-c
  1221.         local abm, bcm, cam = ab.magnitude, bc.magnitude, ca.magnitude
  1222.         local edg1 = math.abs(0.5 + ca:Dot(ab)/(abm*abm))
  1223.         local edg2 = math.abs(0.5 + ab:Dot(bc)/(bcm*bcm))
  1224.         local edg3 = math.abs(0.5 + bc:Dot(ca)/(cam*cam))
  1225.         if edg1 < edg2 then
  1226.             if edg1 >= edg3 then       
  1227.                 a, b, c = c, a, b
  1228.                 ab, bc, ca = ca, ab, bc
  1229.                 abm = cam
  1230.             end
  1231.         else
  1232.             if edg2 < edg3 then
  1233.                 a, b, c = b, c, a
  1234.                 ab, bc, ca = bc, ca, ab
  1235.                 abm = bcm
  1236.             else
  1237.                 a, b, c = c, a, b
  1238.                 ab, bc, ca = ca, ab, bc
  1239.                 abm = cam
  1240.             end
  1241.         end
  1242.      
  1243.         local len1 = -ca:Dot(ab)/abm
  1244.         local len2 = abm - len1
  1245.         local width = (ca + ab.unit*len1).magnitude
  1246.      
  1247.         local maincf = CFrameFromTopBack(a, ab:Cross(bc).unit, -ab.unit)
  1248.      
  1249.         if len1 > 0.2 then
  1250.             mPart1.Parent = parent
  1251.             mPart1.Size = Vector3.new(0.2, width, len1)
  1252.             mPart1.CFrame = maincf*CFrame.Angles(math.pi,0,math.pi/2)*CFrame.new(0,width/2,len1/2)
  1253.         else
  1254.             mPart1.Parent = nil
  1255.         end
  1256.        
  1257.         if len2 > 0.2 then
  1258.             mPart2.Parent = parent
  1259.             mPart2.Size = Vector3.new(0.2, width, len2)
  1260.             mPart2.CFrame = maincf*CFrame.Angles(math.pi,math.pi,-math.pi/2)*CFrame.new(0,width/2,-len1 - len2/2)
  1261.         else
  1262.             mPart2.Parent = nil
  1263.         end
  1264.     end
  1265.     function this:SetProperty(prop, value)
  1266.         mPart1[prop] = value
  1267.         mPart2[prop] = value
  1268.     end
  1269.     this:Set(a, b, c)
  1270.     function this:Destroy()
  1271.         mPart1:Destroy()
  1272.         mPart2:Destroy()
  1273.     end
  1274.     this.p1 = mPart1
  1275.     this.p2 = mPart2
  1276.     this.p1.BrickColor = BrickColor.new(GetDiscoColor(math.noise(0.5, 0.5, this.p1.CFrame.Y * 0.5 + time())))
  1277.     this.p2.BrickColor = BrickColor.new(GetDiscoColor(math.noise(0.5, 0.5, this.p2.CFrame.Y * 0.5 + time())))
  1278.     return this
  1279. end
  1280.  
  1281. function verlet.draw(object, id)
  1282.     if object.class == "Point" then
  1283.         local part = parts[id]
  1284.         part.BrickColor = BrickColor.new(107, 0, 107)
  1285.         part.Transparency = 0
  1286.         part.formFactor = 3
  1287.         part.Anchored = true
  1288.         part.CanCollide = false
  1289.         part.TopSurface = 0
  1290.         part.BottomSurface = 0
  1291.         part.Size = Vector3.new(0.35, 0.35, 0.35)
  1292.         part.Material = "Neon"
  1293.         part.CFrame = CFrame.new(object.position)
  1294.         part.Parent = torso
  1295.         return part
  1296.     elseif object.class == "Link" then
  1297.         local part = parts[id]
  1298.         local dist = (object.point1.position - object.point2.position).magnitude
  1299.         part.Size = Vector3.new(0.2, 0.2, dist)
  1300.         part.CFrame = CFrame.new(object.point1.position, object.point2.position) * CFrame.new(0, 0, dist * -0.5)
  1301.         part.Parent = torso
  1302.         return part
  1303.     end
  1304. end
  1305.  
  1306. function verlet.clear()
  1307.     for _, v in pairs(workspace:GetChildren()) do
  1308.         if v.Name == "Part" then
  1309.             v:Destroy()
  1310.         end
  1311.     end
  1312. end
  1313.  
  1314. local points = {}
  1315. local links = {}
  1316.  
  1317. for x = 0, 2 do
  1318.     points[x] = {}
  1319.     for y = 0, 3 do
  1320.         points[x][y] = verlet.new("Point", torso.Position + Vector3.new(x * 0.8 - 2, 2 - y * 0.8, 5 + y * 0.4))
  1321.         points[x][y].fixed = y == 0
  1322.     end
  1323. end
  1324.  
  1325. for x = 1, 2 do
  1326.     for y = 0, 3 do
  1327.         links[#links + 1] = verlet.new("Link", points[x][y], points[x - 1][y], 1 + y * 0.08)
  1328.     end
  1329. end
  1330.  
  1331. for x = 0, 2 do
  1332.     for y = 1, 3 do
  1333.         links[#links + 1] = verlet.new("Link", points[x][y], points[x][y - 1], 1.2 + y * 0.03)
  1334.     end
  1335. end
  1336.  
  1337. render:connect(function()
  1338.     for x = 0, 2 do
  1339.         for y = 0, 3 do
  1340.             if y == 0 then
  1341.                 points[x][y].position = (torso.CFrame * CFrame.new(x * 1 - 1, 1, 0.5)).p
  1342.             else
  1343.                 points[x][y]:step()
  1344.             end
  1345.         end
  1346.     end
  1347.     for i = 1, #links do
  1348.         links[i]:step()
  1349.     end
  1350.     for i = 1, #tris do
  1351.         triParts[#triParts + 1] = tris[i].p1
  1352.         triParts[#triParts + 1] = tris[i].p2
  1353.     end
  1354.     tris = {}
  1355.     for x = 1, 2 do
  1356.         for y = 1, 3 do
  1357.             tris[#tris + 1] = drawTri(torso, points[x - 1][y - 1].position, points[x - 1][y].position, points[x][y - 1].position)
  1358.             tris[#tris + 1] = drawTri(torso, points[x][y].position, points[x - 1][y].position, points[x][y - 1].position)
  1359.         end
  1360.     end
  1361. end)
Add Comment
Please, Sign In to add comment