DrawingJhon

Imit script

Sep 6th, 2020 (edited)
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.84 KB | None | 0 0
  1. script.Parent = owner.PlayerGui
  2. NLS([==[local remote = script.Parent:WaitForChild("xd")
  3. remote.OnClientInvoke = function()
  4.     for i, v in pairs(owner.Character:findFirstChildOfClass("Humanoid"):GetPlayingAnimationTracks()) do
  5.         v:Stop()
  6.     end
  7. end]==], script)
  8. local RunService = game:GetService("RunService")
  9. local remote = Instance.new("RemoteFunction", script)
  10. remote.Name = "xd"
  11.  
  12. local Imitating = false
  13.  
  14. function play(plr)
  15.     if plr.Character and owner.Character and not Imitating then
  16.         Imitating = plr
  17.         local FINISHED = false
  18.         local plrName = plr.Name
  19.         local plrCharacter = plr.Character
  20.         local root = plr.Character:findFirstChild("HumanoidRootPart")
  21.         local torso = plr.Character:findFirstChild("Torso")
  22.         local hum = plr.Character:findFirstChildOfClass("Humanoid")
  23.  
  24.         local ownerCharacter = owner.Character
  25.         local ownerRoot = owner.Character:findFirstChild("HumanoidRootPart")
  26.         local ownerTorso = owner.Character:findFirstChild("Torso")
  27.         local ownerHum = owner.Character:findFirstChildOfClass("Humanoid")
  28.         local animate = owner.Character:findFirstChild("Animate")
  29.         if animate and animate:IsA("Script") then
  30.             animate.Disabled = true
  31.         end
  32.         local list = {"Right Arm", "Left Arm", "Right Leg", "Left Leg", "Head"}
  33.         local CreatedWelds = {}
  34.         for i, v in pairs(ownerHum:GetPlayingAnimationTracks()) do
  35.             v:Stop()
  36.         end
  37.         remote:InvokeClient(owner)
  38.  
  39.         local function CopyAnimation(track)
  40.             if FINISHED then return end
  41.             if not track then return end
  42.             local newTrack = ownerHum:LoadAnimation(track.Animation)
  43.             newTrack.Looped = track.Looped
  44.             newTrack:Play()
  45.             newTrack.Stopped:Connect(function()
  46.                 newTrack:Stop()
  47.             end)
  48.             coroutine.wrap(function()
  49.                 repeat game:GetService("RunService").Stepped:Wait()
  50.                     newTrack:AdjustSpeed(track.Speed)
  51.                 until FINISHED or not track.IsPlaying
  52.                 newTrack:Stop()
  53.             end)()
  54.         end
  55.  
  56.         for i, v in pairs(hum:GetPlayingAnimationTracks()) do
  57.             CopyAnimation(v)
  58.         end
  59.         hum.AnimationPlayed:Connect(function(track)
  60.             CopyAnimation(track)
  61.         end)
  62.         local function find(torso, part)
  63.             local completed = false
  64.             local wht
  65.             for _, child in pairs(torso:GetChildren()) do
  66.                 if completed then break end
  67.                 if child:IsA("Motor6D") then
  68.                     if child.Part1 ~= nil then
  69.                         if child.Part1.Name == part then
  70.                             wht = child
  71.                             completed = true
  72.                         end
  73.                     end
  74.                 end
  75.             end
  76.             if part == "Torso" then wht = torso end
  77.             return wht
  78.         end
  79.         local function findRoot(root)
  80.             local aw = root:findFirstChildOfClass("Motor6D")
  81.             if aw then
  82.                 if aw.Part0 ~= nil then
  83.                     if aw.Part0.Name == "HumanoidRootPart" then
  84.                         return aw
  85.                     end
  86.                 end
  87.             end
  88.         end
  89.         local function onWeld(weld)
  90.             if not weld:IsA("Weld") or FINISHED then return end
  91.             local newWeld = Instance.new("Weld", ownerCharacter:findFirstChild(weld.Parent.Name))
  92.             table.insert(CreatedWelds, newWeld)
  93.             newWeld.Part0 = ownerCharacter:findFirstChild(weld.Part0.Name)
  94.             newWeld.Part1 = ownerCharacter:findFirstChild(weld.Part1.Name)
  95.             local conn
  96.             conn = game:GetService("RunService").Stepped:Connect(function()
  97.                 if plrCharacter.Parent == nil or ownerCharacter.Parent == nil then FINISHED = true conn:Disconnect() return end
  98.                 newWeld.C0 = weld.C0
  99.                 newWeld.C1 = weld.C1
  100.             end)
  101.         end
  102.         local conn
  103.         conn = game:GetService("RunService").Stepped:Connect(function()
  104.             if plrCharacter.Parent == nil or ownerCharacter.Parent == nil then FINISHED = true conn:Disconnect() return end
  105.             for i, v in pairs(list) do
  106.                 pcall(function()
  107.                     find(ownerTorso, v).C0 = find(torso, v).C0
  108.                     find(ownerTorso, v).C1 = find(torso, v).C1
  109.                 end)
  110.             end
  111.             pcall(function()
  112.                 ownerHum.HipHeight = hum.HipHeight
  113.                 findRoot(ownerRoot).C0 = findRoot(root).C0
  114.                 findRoot(ownerRoot).C1 = findRoot(root).C1
  115.             end)
  116.         end)
  117.         for i, v in pairs(list) do
  118.             for _, weld in pairs(plrCharacter[v]:GetChildren()) do
  119.                 pcall(onWeld, weld)
  120.             end
  121.             plrCharacter[v].ChildAdded:Connect(onWeld)
  122.         end
  123.         for i, v in pairs(torso:GetChildren()) do
  124.             pcall(function()
  125.                 onWeld(v)
  126.             end)
  127.         end
  128.         torso.ChildAdded:Connect(function(p)
  129.             pcall(function()
  130.                 onWeld(p)
  131.             end)
  132.         end)
  133.         repeat wait() until FINISHED
  134.         Imitating = false
  135.         print(plrName.."'s animations ended")
  136.         for i, v in pairs(CreatedWelds) do
  137.             v:Destroy()
  138.         end
  139.         animate.Disabled = false
  140.         ownerHum.HipHeight = 0
  141.     elseif Imitating then
  142.         warn("You are already imitating someone: "..Imitating.Name, 0)
  143.     else
  144.         error("No character found", 0)
  145.     end
  146. end
  147.  
  148. owner.Chatted:Connect(function(msg)
  149.     if msg:sub(1, 3) == "/e " then
  150.         for i, v in pairs(game:GetService("Players"):GetPlayers()) do
  151.             if v.Name:lower():match("^"..msg:sub(4):lower()) and msg:sub(4) ~= "" then
  152.                 if v == owner then
  153.                     error("You can't imitate yourself lmao", 0)
  154.                 end
  155.                 print("HELLO "..v.Name)
  156.                 play(v)
  157.             end
  158.         end
  159.     end
  160. end)
Add Comment
Please, Sign In to add comment