Advertisement
dragonsky77

R15

Jul 31st, 2016
5,385
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.09 KB | None | 1 0
  1. --Do not remove the following line. Used by Plugin by TheNexusAvenger to check if R15 is already ingame.
  2. --R15PortVersionB_
  3.  
  4. local UseShirtHack = false --If true, creates decals to have shirts/pants have proper limb coloring
  5. --The admins will fix it soonish, but for now it isn't
  6. local ModifyHats = false --If true, it will move the hats a little bit to fit the head
  7. --The admins will fix it soonish, but for now it isn't
  8.  
  9.  
  10.  
  11. local function CreateR15Model()
  12. local R15Model = Instance.new("Model")
  13. R15Model.Name = "StarterCharacter"
  14.  
  15. local Humanoid = Instance.new("Humanoid")
  16. Humanoid.HipHeight = 1.8
  17. Humanoid.Parent = R15Model
  18.  
  19. local function CreateLimb(Name,Color,Size,Transparency,ConnectToLimb,MotorName,C0,C1,MeshId)
  20. local Part = Instance.new("Part")
  21. Part.FormFactor = "Custom"
  22. Part.Size = Size
  23. Part.BrickColor = Color
  24. Part.CanCollide = false
  25. Part.Name = Name
  26. Part.Transparency = (Transparency == 0.001 and 0 or Transparency)
  27. Part.TopSurface = "Smooth"
  28. Part.BottomSurface = "Smooth"
  29.  
  30. if ConnectToLimb then
  31. local Motor = Instance.new("Motor6D")
  32. Motor.C0 = C0
  33. Motor.C1 = C1
  34. Motor.Part0 = ConnectToLimb
  35. Motor.Part1 = Part
  36. Motor.Name = MotorName
  37. Motor.MaxVelocity = 0.1
  38. Motor.Parent = ConnectToLimb
  39. end
  40.  
  41. if MeshId then
  42. local Mesh = Instance.new("SpecialMesh")
  43. Mesh.MeshType = "FileMesh"
  44. Mesh.Name = "LimbMesh"
  45. Mesh.MeshId = MeshId
  46. Mesh.Parent = Part
  47. end
  48.  
  49. if MeshId and Transparency == 0.001 then
  50. if UseShirtHack == true then
  51. local Decal = Instance.new("Decal")
  52. Decal.Name = "ShirtDecal"
  53. Decal.Parent = Part
  54. end
  55. end
  56. Part.Parent = R15Model
  57. return Part
  58. end
  59.  
  60. local function AddAttachment(Name,Parent,Position,Rotation,Axis,SecondaryAxis)
  61. local Attachment = Instance.new("Attachment")
  62. Attachment.Position = Position
  63. Attachment.Rotation = Rotation
  64. Attachment.Axis = Axis
  65. Attachment.SecondaryAxis = SecondaryAxis
  66. Attachment.Parent = Parent
  67. end
  68.  
  69.  
  70. local HumanoidRootPart = CreateLimb("HumanoidRootPart",BrickColor.new("Medium stone grey"),Vector3.new(1,1,1),1)
  71. local LowerTorso = CreateLimb("LowerTorso",BrickColor.new("Bright blue"),Vector3.new(1,1,1),0.001,HumanoidRootPart,"RootJoint",CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387941715")
  72. local UpperTorso = CreateLimb("UpperTorso",BrickColor.new("Bright blue"),Vector3.new(1,1,1),0.001,LowerTorso,"Waist",CFrame.new(0, 0.404105991, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387941468")
  73. local Head = CreateLimb("Head",BrickColor.new("Bright yellow"),Vector3.new(1,1,1),0,UpperTorso,"Neck",CFrame.new(0, 1.26949596, 0.0428609997, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, -0.635110021, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387941905")
  74. local LeftUpperArm = CreateLimb("LeftUpperArm",BrickColor.new("Bright yellow"),Vector3.new(1, 0.672, 1),0.001,UpperTorso,"LeftShoulder",CFrame.new(-1.50177097, 0.924546003, 0, 1, 0, -0, 0, 0.999044001, 0.0437170006, 0, -0.0437170006, 0.999044001),CFrame.new(0, 0.336115986, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387938468")
  75. local LeftLowerArm = CreateLimb("LeftLowerArm",BrickColor.new("Bright yellow"),Vector3.new(1, 0.703, 1),0.001,LeftUpperArm,"LeftElbow",CFrame.new(0, -0.336115986, 0, 1, 0, 0, 0, 0.999044001, -0.0437170006, 0, 0.0437170006, 0.999044001),CFrame.new(0, 0.351512015, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387938971")
  76. local LeftHand = CreateLimb("LeftHand",BrickColor.new("Bright yellow"),Vector3.new(1, 0.352, 1),0.001,LeftLowerArm,"LeftWrist",CFrame.new(0, -0.351512015, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0.175756007, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387939233")
  77. local RightUpperArm = CreateLimb("RightUpperArm",BrickColor.new("Bright yellow"),Vector3.new(1, 0.671, 1),0.001,UpperTorso,"RightShoulder",CFrame.new(1.50049305, 0.923726022, 0, 1, 0, -0, 0, 0.999041617, 0.0437709838, 0, -0.0437709838, 0.999041617),CFrame.new(0, 0.335705996, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940113")
  78. local RightLowerArm = CreateLimb("RightLowerArm",BrickColor.new("Bright yellow"),Vector3.new(1, 0.703, 1),0.001,RightUpperArm,"RightElbow",CFrame.new(0, -0.335705996, 0, 1, 0, 0, 0, 0.999041617, -0.0437709838, 0, 0.0437709838, 0.999041617),CFrame.new(0, 0.351512015, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940356")
  79. local RightHand = CreateLimb("RightHand",BrickColor.new("Bright yellow"),Vector3.new(1, 0.352, 1),0.001,RightLowerArm,"RightWrist",CFrame.new(0, -0.351512015, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0.175756007, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940548")
  80. local LeftUpperLeg = CreateLimb("LeftUpperLeg",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.775, 1),0.001,LowerTorso,"LeftHip",CFrame.new(-0.457044005, -0.498115987, 0, 1, 0, -0, 0, 1, 0.000100999998, 0, -0.000100999998, 1),CFrame.new(0, 0.387418985, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387939645")
  81. local LeftLowerLeg = CreateLimb("LeftLowerLeg",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.829, 1),0.001,LeftUpperLeg,"LeftKnee",CFrame.new(0, -0.387418985, 0, 1, 9.95820074e-007, 9.13360125e-008, -9.99999997e-007, 0.995820105, 0.0913360119, 0, -0.0913360119, 0.995820105),CFrame.new(0, 0.414570987, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387939489")
  82. local LeftFoot = CreateLimb("LeftFoot",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.415, 1),0.001,LeftLowerLeg,"LeftAnkle",CFrame.new(0, -0.414570987, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0.207286, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387939912")
  83. local RightUpperLeg = CreateLimb("RightUpperLeg",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.775, 1),0.001,LowerTorso,"RightHip",CFrame.new(0.451141, -0.498115987, 0, 1, 0, -0, 0, 1, 0.000100999998, 0, -0.000100999998, 1),CFrame.new(0, 0.387418985, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940976")
  84. local RightLowerLeg = CreateLimb("RightLowerLeg",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.829, 1),0.001,RightUpperLeg,"RightKnee",CFrame.new(0, -0.387418985, 0, 1, 0, -0, 0, 0.995820105, 0.0913360119, 0, -0.0913360119, 0.995820105),CFrame.new(0, 0.414570987, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940802")
  85. local RightFoot = CreateLimb("RightFoot",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.415, 1),0.001,RightLowerLeg,"RightAnkle",CFrame.new(0, -0.414570987, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0.207286, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387941196")
  86.  
  87. local Torso = CreateLimb("Torso",BrickColor.new("Bright blue"),Vector3.new(1,1,1),1)
  88. local RightArm = CreateLimb("Right Arm",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.2,0.2),1,RightHand,"ToolGripConnector",CFrame.new(0,0.824,0),CFrame.new(0,0,0))
  89. local LeftArm = CreateLimb("Left Arm",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.2,0.2),1,LeftHand,"ToolGripConnector",CFrame.new(0,0.824,0),CFrame.new(0,0,0))
  90.  
  91.  
  92.  
  93. AddAttachment("NeckRigAttachment",Head,Vector3.new(0, -0.635110021, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  94. AddAttachment("HatAttachment",Head,Vector3.new(0.00058599998, 0.502066016, -0.0712800026),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  95. AddAttachment("HairAttachment",Head,Vector3.new(0.00058599998, 0.502066016, -0.0712800026),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  96. AddAttachment("FaceAttachment",Head,Vector3.new(0.0161419995, -0.0170900002, -0.671580017),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  97. AddAttachment("NeckAttachment",Head,Vector3.new(0.000548999989, -0.689900994, -0.025719),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  98. AddAttachment("RootRigAttachment",HumanoidRootPart,Vector3.new(0, 0, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  99. AddAttachment("LeftElbowRigAttachment",LeftLowerArm,Vector3.new(0, 0.351512015, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  100. AddAttachment("LeftWristRigAttachment",LeftLowerArm,Vector3.new(0, -0.351512015, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  101. AddAttachment("LeftShoulderRigAttachment",LeftUpperArm,Vector3.new(0, 0.336115986, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  102. AddAttachment("LeftElbowRigAttachment",LeftUpperArm,Vector3.new(0, -0.336115986, 0),Vector3.new(2.50559807, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 0.999044001, 0.0437170006))
  103. AddAttachment("LeftAnkleRigAttachment",LeftFoot,Vector3.new(0, 0.207286, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  104. AddAttachment("LeftWristRigAttachment",LeftHand,Vector3.new(0, 0.175756007, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  105. AddAttachment("LeftGripAttachment",LeftHand,Vector3.new(0, -0.162433997, 0),Vector3.new(-90, -0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 0, -1))
  106. AddAttachment("LeftKneeRigAttachment",LeftLowerLeg,Vector3.new(0, 0.414570987, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  107. AddAttachment("LeftAnkleRigAttachment",LeftLowerLeg,Vector3.new(0, -0.414570987, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  108. AddAttachment("LeftHipRigAttachment",LeftUpperLeg,Vector3.new(0, 0.387418985, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  109. AddAttachment("LeftKneeRigAttachment",LeftUpperLeg,Vector3.new(0, -0.387418985, 0),Vector3.new(-5.24047184, 5.23316794e-006, -5.70562879e-005),Vector3.new(1, -9.99999997e-007, 0),Vector3.new(9.95820074e-007, 0.995820105, -0.0913360119))
  110. AddAttachment("RightElbowRigAttachment",RightLowerArm,Vector3.new(0, 0.351512015, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  111. AddAttachment("RightWristRigAttachment",RightLowerArm,Vector3.new(0, -0.351512015, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  112. AddAttachment("RightShoulderRigAttachment",RightUpperArm,Vector3.new(0, 0.335705996, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  113. AddAttachment("RightElbowRigAttachment",RightUpperArm,Vector3.new(0, -0.335705996, 0),Vector3.new(2.50869417, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 0.999041617, 0.0437709838))
  114. AddAttachment("RightAnkleRigAttachment",RightFoot,Vector3.new(0, 0.207286, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  115. AddAttachment("RightWristRigAttachment",RightHand,Vector3.new(0, 0.175756007, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  116. AddAttachment("RightGripAttachment",RightHand,Vector3.new(0, -0.162433997, 0),Vector3.new(-90, -0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 0, -1))
  117. AddAttachment("RightKneeRigAttachment",RightLowerLeg,Vector3.new(0, 0.414570987, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  118. AddAttachment("RightAnkleRigAttachment",RightLowerLeg,Vector3.new(0, -0.414570987, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  119. AddAttachment("RightHipRigAttachment",RightUpperLeg,Vector3.new(0, 0.387418985, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  120. AddAttachment("RightKneeRigAttachment",RightUpperLeg,Vector3.new(0, -0.387418985, 0),Vector3.new(-5.24047184, -0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 0.995820105, -0.0913360119))
  121. AddAttachment("WaistRigAttachment",UpperTorso,Vector3.new(0, 0, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  122. AddAttachment("NeckRigAttachment",UpperTorso,Vector3.new(0, 1.26949596, 0.0428609997),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  123. AddAttachment("LeftShoulderRigAttachment",UpperTorso,Vector3.new(-1.50177097, 0.924546003, 0),Vector3.new(-2.50559807, -0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 0.999044001, -0.0437170006))
  124. AddAttachment("RightShoulderRigAttachment",UpperTorso,Vector3.new(1.50049305, 0.923726022, 0),Vector3.new(-2.50869417, -0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 0.999041617, -0.0437709838))
  125. AddAttachment("BodyBackAttachment",UpperTorso,Vector3.new(0.000597000006, 0.362652004, 0.488660008),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  126. AddAttachment("BodyFrontAttachment",UpperTorso,Vector3.new(0.00511999987, 0.606338978, -0.510424972),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  127. AddAttachment("ShoulderAttachment",UpperTorso,Vector3.new(-0.797239006, 1.21844196, -0.00955600012),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  128. AddAttachment("RootRigAttachment",LowerTorso,Vector3.new(0, 0, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  129. AddAttachment("WaistRigAttachment",LowerTorso,Vector3.new(0, 0.404105991, 0),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  130. AddAttachment("LeftHipRigAttachment",LowerTorso,Vector3.new(-0.457044005, -0.498115987, 0),Vector3.new(-0.00578687387, -0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, -0.000100999998))
  131. AddAttachment("RightHipRigAttachment",LowerTorso,Vector3.new(0.451141, -0.498115987, 0),Vector3.new(-0.00578687387, -0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, -0.000100999998))
  132. AddAttachment("WaistAttachment",LowerTorso,Vector3.new(0.00511999987, 0.00413900008, -0.510424972),Vector3.new(-0, 0, -0),Vector3.new(1, 0, 0),Vector3.new(0, 1, 0))
  133.  
  134.  
  135. R15Model.PrimaryPart = HumanoidRootPart
  136.  
  137. return R15Model
  138. end
  139.  
  140. local Animate = script:WaitForChild("Animate")
  141. local R15Fixes = script:WaitForChild("R15Fixes")
  142. local StarterPlayer = game:GetService("StarterPlayer")
  143. local R15Model = CreateR15Model()
  144.  
  145. local NewAnimate = Animate:Clone()
  146. NewAnimate.Disabled = false
  147. NewAnimate.Parent = StarterPlayer:WaitForChild("StarterCharacterScripts")
  148.  
  149. local NewR15Fixes = R15Fixes:Clone()
  150. NewR15Fixes.Disabled = false
  151. NewR15Fixes.Parent = R15Model
  152.  
  153. if ModifyHats == true then
  154. local Bool = Instance.new("BoolValue")
  155. Bool.Name = "ModifyHats"
  156. Bool.Value = true
  157. Bool.Parent = NewR15Fixes
  158. end
  159.  
  160. R15Model.Parent = StarterPlayer
  161. local Character = script.Parent
  162. local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
  163. local Torso = Character:WaitForChild("Torso")
  164. local Humanoid = Character:WaitForChild("Humanoid")
  165.  
  166. local function ChildAddedJoint(Ins)
  167. if Ins:IsA("Motor6D") then
  168. if Ins.Part1 then
  169. if Ins.Part1.Name == "Right Arm" or Ins.Part1.Name == "Left Arm" then
  170. Ins.Part1 = nil
  171. elseif Ins.Part1.Name == "Torso" then
  172. Ins:Destroy()
  173. end
  174. end
  175. end
  176. end
  177.  
  178. HumanoidRootPart.ChildAdded:connect(ChildAddedJoint)
  179. for _,Ins in pairs(HumanoidRootPart:GetChildren()) do
  180. spawn(function() ChildAddedJoint(Ins) end)
  181. end
  182. Torso.ChildAdded:connect(ChildAddedJoint)
  183. for _,Ins in pairs(Torso:GetChildren()) do
  184. spawn(function() ChildAddedJoint(Ins) end)
  185. end
  186.  
  187. local Head = Character:WaitForChild("Head")
  188. local UpperTorso = Character:WaitForChild("UpperTorso")
  189. local RightUpperLeg = Character:WaitForChild("RightUpperLeg")
  190. local UpperTorsoDecal = UpperTorso:FindFirstChild("ShirtDecal")
  191. local UpperTorsoMesh
  192. if not UpperTorsoDecal then
  193. UpperTorsoMesh = UpperTorso:FindFirstChild("LimbMesh")
  194. end
  195. local RightUpperLegDecal = RightUpperLeg:FindFirstChild("ShirtDecal")
  196. local RightUpperLegMesh
  197. if not RightUpperLegDecal then
  198. RightUpperLegMesh = RightUpperLeg:FindFirstChild("LimbMesh")
  199. end
  200.  
  201.  
  202. local RightHand =Character:WaitForChild("RightHand")
  203. local Limbs = {
  204. Torso = {
  205. Character:WaitForChild("LowerTorso"),
  206. UpperTorso,
  207. },
  208. LeftArm = {
  209. Character:WaitForChild("LeftUpperArm"),
  210. Character:WaitForChild("LeftLowerArm"),
  211. Character:WaitForChild("LeftHand"),
  212. },
  213. RightArm = {
  214. Character:WaitForChild("RightUpperArm"),
  215. Character:WaitForChild("RightLowerArm"),
  216. RightHand,
  217. },
  218. LeftLeg = {
  219. Character:WaitForChild("LeftUpperLeg"),
  220. Character:WaitForChild("LeftLowerLeg"),
  221. Character:WaitForChild("LeftFoot"),
  222. },
  223. RightLeg = {
  224. Character:WaitForChild("RightUpperLeg"),
  225. Character:WaitForChild("RightLowerLeg"),
  226. Character:WaitForChild("RightFoot"),
  227. },
  228. }
  229.  
  230.  
  231. local function ChangePart(LimbName,Property)
  232. for _,Limb in pairs(Limbs[LimbName]) do
  233. if type(Property) == "string" then
  234. local ShirtDecal = Limb:FindFirstChild("ShirtDecal")
  235. if ShirtDecal then
  236. ShirtDecal.Texture = Property
  237. else
  238. local Mesh = Limb:FindFirstChild("LimbMesh")
  239. if Mesh then
  240. Mesh.TextureId = Property
  241. end
  242. end
  243. else
  244. Limb.BrickColor = Property
  245. end
  246. end
  247. end
  248.  
  249. local RightGrip
  250. local function ChildAdded(Ins)
  251. if Ins:IsA("BodyColors") then
  252. Head.BrickColor = Ins.HeadColor
  253. ChangePart("Torso",Ins.TorsoColor)
  254. ChangePart("LeftArm",Ins.LeftArmColor)
  255. ChangePart("RightArm",Ins.RightArmColor)
  256. ChangePart("LeftLeg",Ins.LeftLegColor)
  257. ChangePart("RightLeg",Ins.RightLegColor)
  258. elseif Ins:IsA("Shirt") then
  259. ChangePart("Torso",Ins.ShirtTemplate)
  260. ChangePart("LeftArm",Ins.ShirtTemplate)
  261. ChangePart("RightArm",Ins.ShirtTemplate)
  262. elseif Ins:IsA("Pants") then
  263. if (UpperTorsoDecal and UpperTorsoDecal.Texture == "") or (UpperTorsoMesh and UpperTorsoMesh.TextureId == "") then
  264. ChangePart("Torso",Ins.PantsTemplate)
  265. ChangePart("LeftLeg",Ins.PantsTemplate)
  266. ChangePart("RightLeg",Ins.PantsTemplate)
  267. else
  268. ChangePart("LeftLeg",Ins.PantsTemplate)
  269. ChangePart("RightLeg",Ins.PantsTemplate)
  270. end
  271. end
  272. end
  273.  
  274. local function ChildRemoved(Ins)
  275. if Ins:IsA("Shirt") then
  276. local PantsTexture = (RightUpperLegDecal and RightUpperLegDecal.Texture) or (RightUpperLegMesh and RightUpperLegMesh.TextureId)
  277. ChangePart("Torso",PantsTexture)
  278. ChangePart("LeftArm","")
  279. ChangePart("RightArm","")
  280. elseif Ins:IsA("Pants") then
  281. local ShirtTexture = (UpperTorsoDecal and UpperTorsoDecal.Texture) or (UpperTorsoMesh and UpperTorsoMesh.TextureId)
  282. ChangePart("LeftLeg","")
  283. ChangePart("RightLeg","")
  284. if ShirtTexture == Ins.PantsTemplate then ChangePart("Torso","") end
  285. end
  286. end
  287.  
  288. Character.ChildAdded:connect(ChildAdded)
  289. Character.ChildRemoved:connect(ChildRemoved)
  290. for _,Ins in pairs(Character:GetChildren()) do
  291. spawn(function() ChildAdded(Ins) end)
  292. end
  293.  
  294.  
  295.  
  296.  
  297.  
  298. if script:FindFirstChild("ModifyHats") then
  299. local function HeadWeldAdded(Ins)
  300. if Ins.Name == "HeadWeld" then
  301. Ins.C1 = CFrame.new(0,0,0.05) * Ins.C1
  302. end
  303. end
  304.  
  305. Head.ChildAdded:connect(HeadWeldAdded)
  306. for _,Ins in pairs(Character:GetChildren()) do
  307. spawn(function() HeadWeldAdded(Ins) end)
  308. end
  309. end
  310. function waitForChild(parent, childName)
  311. local child = parent:findFirstChild(childName)
  312. if child then return child end
  313. while true do
  314. child = parent.ChildAdded:wait()
  315. if child.Name==childName then return child end
  316. end
  317. end
  318.  
  319. local Figure = script.Parent
  320. local Humanoid = waitForChild(Figure, "Humanoid")
  321. local pose = "Standing"
  322. Humanoid.CameraOffset = Vector3.new(0,0.5,0)
  323.  
  324. local currentAnim = ""
  325. local currentAnimInstance = nil
  326. local currentAnimTrack = nil
  327. local currentAnimKeyframeHandler = nil
  328. local currentAnimSpeed = 1.0
  329. local animTable = {}
  330. local animNames = {
  331. idle = {
  332. { id = "rbxasset://R15021216/idle_stretch.xml", weight = 1 },
  333. { id = "rbxasset://R15021216/idle_look.xml", weight = 1 },
  334. { id = "rbxasset://R15021216/idle.xml", weight = 9 }
  335. },
  336. walk = {
  337. { id = "rbxasset://R15021216/run.xml", weight = 10 }
  338. },
  339. run = {
  340. { id = "rbxasset://R15021216/run.xml", weight = 10 }
  341. },
  342. jump = {
  343. { id = "rbxasset://R15021216/jump.xml", weight = 10 }
  344. },
  345. fall = {
  346. { id = "rbxasset://R15021216/falling.xml", weight = 10 }
  347. },
  348. climb = {
  349. { id = "rbxasset://R15021216/climb.xml", weight = 10 }
  350. },
  351. sit = {
  352. { id = "http://www.roblox.com/asset/?id=393915321", weight = 10 }
  353. },
  354. toolnone = {
  355. { id = "http://www.roblox.com/asset/?id=393915542", weight = 10 }
  356. },
  357. toolslash = {
  358. { id = "http://www.roblox.com/asset/?id=393915542", weight = 10 }
  359. -- { id = "slash.xml", weight = 10 }
  360. },
  361. toollunge = {
  362. { id = "http://www.roblox.com/asset/?id=393915542", weight = 10 }
  363. },
  364. wave = {
  365. { id = "http://www.roblox.com/asset/?id=393915710", weight = 10 }
  366. },
  367. point = {
  368. { id = "http://www.roblox.com/asset/?id=393915866", weight = 10 }
  369. },
  370. dance = {
  371. { id = "http://www.roblox.com/asset/?id=393916260", weight = 10 },
  372. { id = "http://www.roblox.com/asset/?id=393916456", weight = 10 },
  373. { id = "http://www.roblox.com/asset/?id=393916635", weight = 10 }
  374. },
  375. dance2 = {
  376. { id = "http://www.roblox.com/asset/?id=393916791", weight = 10 },
  377. { id = "http://www.roblox.com/asset/?id=393916989", weight = 10 },
  378. { id = "http://www.roblox.com/asset/?id=393917195", weight = 10 }
  379. },
  380. dance3 = {
  381. { id = "http://www.roblox.com/asset/?id=393917375", weight = 10 },
  382. { id = "http://www.roblox.com/asset/?id=393917556", weight = 10 },
  383. { id = "http://www.roblox.com/asset/?id=393917721", weight = 10 }
  384. },
  385. laugh = {
  386. { id = "http://www.roblox.com/asset/?id=393916166", weight = 10 }
  387. },
  388. cheer = {
  389. { id = "http://www.roblox.com/asset/?id=393916016", weight = 10 }
  390. },
  391. }
  392.  
  393. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  394. local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
  395.  
  396. math.randomseed(tick())
  397.  
  398. function configureAnimationSet(name, fileList)
  399. if (animTable[name] ~= nil) then
  400. for _, connection in pairs(animTable[name].connections) do
  401. connection:disconnect()
  402. end
  403. end
  404. animTable[name] = {}
  405. animTable[name].count = 0
  406. animTable[name].totalWeight = 0
  407. animTable[name].connections = {}
  408.  
  409. -- check for config values
  410. local config = script:FindFirstChild(name)
  411. if (config ~= nil) then
  412. -- print("Loading anims " .. name)
  413. table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  414. table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  415. local idx = 1
  416. for _, childPart in pairs(config:GetChildren()) do
  417. if (childPart:IsA("Animation")) then
  418. table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  419. animTable[name][idx] = {}
  420. animTable[name][idx].anim = childPart
  421. local weightObject = childPart:FindFirstChild("Weight")
  422. if (weightObject == nil) then
  423. animTable[name][idx].weight = 1
  424. else
  425. animTable[name][idx].weight = weightObject.Value
  426. end
  427. animTable[name].count = animTable[name].count + 1
  428. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  429. -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  430. idx = idx + 1
  431. end
  432. end
  433. end
  434.  
  435. -- fallback to defaults
  436. if (animTable[name].count <= 0) then
  437. for idx, anim in pairs(fileList) do
  438. animTable[name][idx] = {}
  439. animTable[name][idx].anim = Instance.new("Animation")
  440. animTable[name][idx].anim.Name = name
  441. animTable[name][idx].anim.AnimationId = anim.id
  442. animTable[name][idx].weight = anim.weight
  443. animTable[name].count = animTable[name].count + 1
  444. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  445. -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  446. end
  447. end
  448. end
  449.  
  450. -- Setup animation objects
  451. function scriptChildModified(child)
  452. local fileList = animNames[child.Name]
  453. if (fileList ~= nil) then
  454. configureAnimationSet(child.Name, fileList)
  455. end
  456. end
  457.  
  458. script.ChildAdded:connect(scriptChildModified)
  459. script.ChildRemoved:connect(scriptChildModified)
  460.  
  461.  
  462. for name, fileList in pairs(animNames) do
  463. configureAnimationSet(name, fileList)
  464. end
  465.  
  466. -- ANIMATION
  467.  
  468. -- declarations
  469. local toolAnim = "None"
  470. local toolAnimTime = 0
  471.  
  472. local jumpAnimTime = 0
  473. local jumpAnimDuration = 0.31
  474.  
  475. local toolTransitionTime = 0.1
  476. local fallTransitionTime = 0.2
  477.  
  478. -- functions
  479.  
  480. function stopAllAnimations()
  481. local oldAnim = currentAnim
  482.  
  483. -- return to idle if finishing an emote
  484. if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  485. oldAnim = "idle"
  486. end
  487.  
  488. currentAnim = ""
  489. currentAnimInstance = nil
  490. if (currentAnimKeyframeHandler ~= nil) then
  491. currentAnimKeyframeHandler:disconnect()
  492. end
  493.  
  494. if (currentAnimTrack ~= nil) then
  495. currentAnimTrack:Stop()
  496. currentAnimTrack:Destroy()
  497. currentAnimTrack = nil
  498. end
  499. return oldAnim
  500. end
  501.  
  502. function setAnimationSpeed(speed)
  503. if speed ~= currentAnimSpeed then
  504. currentAnimSpeed = speed
  505. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  506. end
  507. end
  508.  
  509. function keyFrameReachedFunc(frameName)
  510. if (frameName == "End") then
  511. -- print("Keyframe : ".. frameName)
  512.  
  513. local repeatAnim = currentAnim
  514. -- return to idle if finishing an emote
  515. if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
  516. repeatAnim = "idle"
  517. end
  518.  
  519. local animSpeed = currentAnimSpeed
  520. playAnimation(repeatAnim, 0.15, Humanoid)
  521. setAnimationSpeed(animSpeed)
  522. end
  523. end
  524.  
  525. -- Preload animations
  526. function playAnimation(animName, transitionTime, humanoid)
  527.  
  528. local roll = math.random(1, animTable[animName].totalWeight)
  529. local origRoll = roll
  530. local idx = 1
  531. while (roll > animTable[animName][idx].weight) do
  532. roll = roll - animTable[animName][idx].weight
  533. idx = idx + 1
  534. end
  535.  
  536. -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  537.  
  538. local anim = animTable[animName][idx].anim
  539.  
  540. -- switch animation
  541. if (anim ~= currentAnimInstance) then
  542.  
  543. if (currentAnimTrack ~= nil) then
  544. currentAnimTrack:Stop(transitionTime)
  545. currentAnimTrack:Destroy()
  546. end
  547.  
  548. currentAnimSpeed = 1.0
  549.  
  550. -- load it to the humanoid; get AnimationTrack
  551. currentAnimTrack = humanoid:LoadAnimation(anim)
  552.  
  553. -- play the animation
  554. currentAnimTrack:Play(transitionTime)
  555. currentAnim = animName
  556. currentAnimInstance = anim
  557.  
  558. -- set up keyframe name triggers
  559. if (currentAnimKeyframeHandler ~= nil) then
  560. currentAnimKeyframeHandler:disconnect()
  561. end
  562. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  563.  
  564. end
  565.  
  566. end
  567.  
  568. -------------------------------------------------------------------------------------------
  569. -------------------------------------------------------------------------------------------
  570.  
  571. local toolAnimName = ""
  572. local toolAnimTrack = nil
  573. local toolAnimInstance = nil
  574. local currentToolAnimKeyframeHandler = nil
  575.  
  576. function toolKeyFrameReachedFunc(frameName)
  577. if (frameName == "End") then
  578. -- print("Keyframe : ".. frameName)
  579. playToolAnimation(toolAnimName, 0.0, Humanoid)
  580. end
  581. end
  582.  
  583.  
  584. function playToolAnimation(animName, transitionTime, humanoid)
  585.  
  586. local roll = math.random(1, animTable[animName].totalWeight)
  587. local origRoll = roll
  588. local idx = 1
  589. while (roll > animTable[animName][idx].weight) do
  590. roll = roll - animTable[animName][idx].weight
  591. idx = idx + 1
  592. end
  593. -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  594. local anim = animTable[animName][idx].anim
  595.  
  596. if (toolAnimInstance ~= anim) then
  597.  
  598. if (toolAnimTrack ~= nil) then
  599. toolAnimTrack:Stop()
  600. toolAnimTrack:Destroy()
  601. transitionTime = 0
  602. end
  603.  
  604. -- load it to the humanoid; get AnimationTrack
  605. toolAnimTrack = humanoid:LoadAnimation(anim)
  606.  
  607. -- play the animation
  608. toolAnimTrack:Play(transitionTime)
  609. toolAnimName = animName
  610. toolAnimInstance = anim
  611.  
  612. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  613. end
  614. end
  615.  
  616. function stopToolAnimations()
  617. local oldAnim = toolAnimName
  618.  
  619. if (currentToolAnimKeyframeHandler ~= nil) then
  620. currentToolAnimKeyframeHandler:disconnect()
  621. end
  622.  
  623. toolAnimName = ""
  624. toolAnimInstance = nil
  625. if (toolAnimTrack ~= nil) then
  626. toolAnimTrack:Stop()
  627. toolAnimTrack:Destroy()
  628. toolAnimTrack = nil
  629. end
  630.  
  631.  
  632. return oldAnim
  633. end
  634.  
  635. -------------------------------------------------------------------------------------------
  636. -------------------------------------------------------------------------------------------
  637.  
  638.  
  639. function onRunning(speed)
  640. if speed>0.01 then
  641. local scale = 15.0
  642. playAnimation("walk", 0.1, Humanoid)
  643. setAnimationSpeed(speed / scale)
  644. pose = "Running"
  645. else
  646. playAnimation("idle", 0.1, Humanoid)
  647. pose = "Standing"
  648. end
  649. end
  650.  
  651. function onDied()
  652. pose = "Dead"
  653. end
  654.  
  655. function onJumping()
  656. playAnimation("jump", 0.1, Humanoid)
  657. jumpAnimTime = jumpAnimDuration
  658. pose = "Jumping"
  659. end
  660.  
  661. function onClimbing(speed)
  662. local scale = 2.0
  663. playAnimation("climb", 0.1, Humanoid)
  664. setAnimationSpeed(speed / scale)
  665. pose = "Climbing"
  666. end
  667.  
  668. function onGettingUp()
  669. pose = "GettingUp"
  670. end
  671.  
  672. function onFreeFall()
  673. if (jumpAnimTime <= 0) then
  674. playAnimation("fall", fallTransitionTime, Humanoid)
  675. end
  676. pose = "FreeFall"
  677. end
  678.  
  679. function onFallingDown()
  680. pose = "FallingDown"
  681. end
  682.  
  683. function onSeated()
  684. pose = "Seated"
  685. end
  686.  
  687. function onPlatformStanding()
  688. pose = "PlatformStanding"
  689. end
  690.  
  691. function onSwimming(speed)
  692. if speed>0 then
  693. pose = "Running"
  694. else
  695. pose = "Standing"
  696. end
  697. end
  698.  
  699. function getTool()
  700. for _, kid in ipairs(Figure:GetChildren()) do
  701. if kid.className == "Tool" then return kid end
  702. end
  703. return nil
  704. end
  705.  
  706. function getToolAnim(tool)
  707. for _, c in ipairs(tool:GetChildren()) do
  708. if c.Name == "toolanim" and c.className == "StringValue" then
  709. return c
  710. end
  711. end
  712. return nil
  713. end
  714.  
  715. function animateTool()
  716.  
  717. if (toolAnim == "None") then
  718. playToolAnimation("toolnone", toolTransitionTime, Humanoid)
  719. return
  720. end
  721.  
  722. if (toolAnim == "Slash") then
  723. playToolAnimation("toolslash", 0, Humanoid)
  724. return
  725. end
  726.  
  727. if (toolAnim == "Lunge") then
  728. playToolAnimation("toollunge", 0, Humanoid)
  729. return
  730. end
  731. end
  732.  
  733. function moveSit()
  734. RightShoulder.MaxVelocity = 0.15
  735. LeftShoulder.MaxVelocity = 0.15
  736. RightShoulder:SetDesiredAngle(3.14 /2)
  737. LeftShoulder:SetDesiredAngle(-3.14 /2)
  738. RightHip:SetDesiredAngle(3.14 /2)
  739. LeftHip:SetDesiredAngle(-3.14 /2)
  740. end
  741.  
  742. local lastTick = 0
  743.  
  744. function move(time)
  745. local amplitude = 1
  746. local frequency = 1
  747. local deltaTime = time - lastTick
  748. lastTick = time
  749.  
  750. local climbFudge = 0
  751. local setAngles = false
  752.  
  753. if (jumpAnimTime > 0) then
  754. jumpAnimTime = jumpAnimTime - deltaTime
  755. end
  756.  
  757. if (pose == "FreeFall" and jumpAnimTime <= 0) then
  758. playAnimation("fall", fallTransitionTime, Humanoid)
  759. elseif (pose == "Seated") then
  760. playAnimation("sit", 0.5, Humanoid)
  761. return
  762. elseif (pose == "Running") then
  763. playAnimation("walk", 0.1, Humanoid)
  764. elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  765. stopAllAnimations()
  766. amplitude = 0.1
  767. frequency = 1
  768. setAngles = true
  769. end
  770.  
  771. -- Tool Animation handling
  772. local tool = getTool()
  773. if tool then
  774.  
  775. animStringValueObject = getToolAnim(tool)
  776.  
  777. if animStringValueObject then
  778. toolAnim = animStringValueObject.Value
  779. -- message recieved, delete StringValue
  780. animStringValueObject.Parent = nil
  781. toolAnimTime = time + .3
  782. end
  783.  
  784. if time > toolAnimTime then
  785. toolAnimTime = 0
  786. toolAnim = "None"
  787. end
  788.  
  789. animateTool()
  790. else
  791. stopToolAnimations()
  792. toolAnim = "None"
  793. toolAnimInstance = nil
  794. toolAnimTime = 0
  795. end
  796. end
  797.  
  798. -- connect events
  799. Humanoid.Died:connect(onDied)
  800. Humanoid.Running:connect(onRunning)
  801. Humanoid.Jumping:connect(onJumping)
  802. Humanoid.Climbing:connect(onClimbing)
  803. Humanoid.GettingUp:connect(onGettingUp)
  804. Humanoid.FreeFalling:connect(onFreeFall)
  805. Humanoid.FallingDown:connect(onFallingDown)
  806. Humanoid.Seated:connect(onSeated)
  807. Humanoid.PlatformStanding:connect(onPlatformStanding)
  808. Humanoid.Swimming:connect(onSwimming)
  809.  
  810. -- setup emote chat hook
  811. Game.Players.LocalPlayer.Chatted:connect(function(msg)
  812. local emote = ""
  813. if (string.sub(msg, 1, 3) == "/e ") then
  814. emote = string.sub(msg, 4)
  815. elseif (string.sub(msg, 1, 7) == "/emote ") then
  816. emote = string.sub(msg, 8)
  817. end
  818.  
  819. if (pose == "Standing" and emoteNames[emote] ~= nil) then
  820. playAnimation(emote, 0.1, Humanoid)
  821. end
  822. -- print("===> " .. string.sub(msg, 1, 3) .. "(" .. emote .. ")")
  823. end)
  824.  
  825.  
  826. -- main program
  827.  
  828. local runService = game:service("RunService");
  829.  
  830. -- print("bottom")
  831.  
  832. -- initialize to idle
  833. playAnimation("idle", 0.1, Humanoid)
  834. pose = "Standing"
  835.  
  836. while Figure.Parent~=nil do
  837. local _, time = wait(0.1)
  838. move(time)
  839. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement