Advertisement
Extreezy

Shield Script

Dec 15th, 2017
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. wait(.1)
  2. print('Beginning of shield')
  3. Player = game.Players.LocalPlayer
  4. Character = Player.Character
  5. LArm = Character:WaitForChild("LeftArm", 10)
  6. Torso = Character:WaitForChild("UpperTorso", 10)
  7. Shoulder = Character:FindFirstChild('LeftUpperArm', 10)--Torso:FindFirstChild("Left Shoulder")
  8.  
  9. ShieldTemplate = script:WaitForChild("ShieldTemplate", 10)
  10. VariantShield = script:WaitForChild("VariantShield", 10)
  11. RemoveFunction = script:WaitForChild("RemoveShield", 10)
  12.  
  13. Use = false
  14. DataY = 0
  15. Up = false
  16. Down = false
  17. Busy = false
  18. AnimationSpeed = 10 -- Slower, smoother with more integers
  19.  
  20. ShieldLink = nil
  21. Weld = nil
  22. LeftShoulderMotor = nil
  23.  
  24. local function WeldDecoration(Variant, WeldTo)
  25. local g = Variant:Clone()
  26. g.Parent = WeldTo.Parent
  27. local C = g:GetChildren()
  28. for i = 1, #C do
  29. if C[i]:IsA("BasePart") then
  30. C[i].CanCollide = true
  31. local W = Instance.new("Weld")
  32. W.Part0 = g.Middle
  33. W.Part1 = C[i]
  34. local CJ = CFrame.new(g.Middle.Position)
  35. local C0 = g.Middle.CFrame:inverse()*CJ
  36. local C1 = C[i].CFrame:inverse()*CJ
  37. W.C0 = C0
  38. W.C1 = C1
  39. W.Parent = g.Middle
  40. end
  41.  
  42. local Y = Instance.new("Weld")
  43. Y.Part0 = WeldTo
  44. Y.Part1 = g.Middle
  45. Y.C0 = CFrame.new(0, 0, 0)
  46. Y.Parent = Y.Part0
  47. end
  48.  
  49. local h = g:GetChildren()
  50. for i = 1, # h do
  51. h[i].Anchored = false
  52. h[i].CanCollide = false
  53. end
  54. end
  55.  
  56. local function CreateShield()
  57. local Shield = ShieldTemplate:Clone()
  58. Shield.Name = "Shield"
  59. Shield.Parent = Character
  60. WeldDecoration(VariantShield, Shield.Handle)
  61. --Shield:MoveTo(Character.UpperTorso.Position)
  62. ShieldWeld = Instance.new("Weld", Shield)
  63. ShieldWeld.Part0 = LArm
  64. ShieldWeld.Part1 = Shield.Handle
  65.  
  66. local ShieldTag = Instance.new("StringValue", ShieldTemplate.Handle)
  67. ShieldTag.Name = "IsShield"
  68. ShieldTag.Value = "Wood"
  69.  
  70. ShieldWeld.C0 = CFrame.new(-0.175, -0.1, 0) * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(90), 0)
  71. ShieldLink = Shield
  72. print('shield created')
  73. end
  74.  
  75. function CommandIssued(Type, Data)
  76.  
  77. if Type == "KeyPress" and Data ~= nil then
  78. local Key = Data:lower()
  79.  
  80. if Key == "f" then
  81. print('creating shield')
  82. CreateShield()
  83. end
  84.  
  85. if Key == "q" then
  86. if not Use and not Busy then
  87. Busy = true
  88. if not Character:FindFirstChild("Shield") then
  89. CreateShield()
  90. end
  91. LeftShoulderMotor = Shoulder -- Save data
  92. --Shoulder:Destroy() -- Disconnect arm from shoulder
  93. Weld = Instance.new("Weld") -- New Weld LeftArm to Torso
  94. Weld.Name = "LeftArm Weld"
  95. Weld.Part0 = LArm
  96. Weld.Part1 = ShieldTemplate.Handle
  97. Weld.Parent = Torso
  98. Weld.C0 = CFrame.new(-1.5,0,0) -- Reposition arm
  99.  
  100. for i = 1,AnimationSpeed do
  101. Weld.C0 = Weld.C0 * CFrame.new(0.5/AnimationSpeed,-0.25/AnimationSpeed,-1/AnimationSpeed)*CFrame.fromEulerAnglesXYZ(math.rad(70/AnimationSpeed),math.rad(-40/AnimationSpeed),math.rad(40/AnimationSpeed)) -- if you tweak the numbers long enough you manage to get a smooth animation, sometimes it takes really long until you finally get all the positions right but when it comes to cframe/Weld manipulation the best way to achieve the wanted formula is trough trial and error
  102. wait()
  103. end
  104.  
  105. Busy = false
  106. Use = true
  107. else
  108. if not Busy then
  109. Busy = true
  110. if DataY > 0 then
  111. for i = 1, DataY do
  112. DataY = DataY - 1
  113. Weld.C0 = Weld.C0 * CFrame.new(0,0,0.04)*CFrame.fromEulerAnglesXYZ(math.rad(-3),math.rad(1),math.rad(0))
  114. if ShieldWeld ~= nil then
  115. ShieldWeld.C0 = ShieldWeld.C0 * CFrame.new(.02, 0, .015) * CFrame.fromEulerAnglesXYZ(math.rad(.9), math.rad(-2), math.rad(.75)) -- SHIELD WELD HERE
  116. end
  117. wait()
  118. end
  119. end
  120. for i = 1, AnimationSpeed do
  121. Weld.C0 = Weld.C0*CFrame.new(-0.5/AnimationSpeed,0.25/AnimationSpeed,1/AnimationSpeed)*CFrame.fromEulerAnglesXYZ(math.rad(-70/AnimationSpeed),math.rad(40/AnimationSpeed),math.rad(-40/AnimationSpeed)) -- the equiping animation reversed
  122. wait()
  123. end
  124. ShieldWeld.C0 = CFrame.new(-0.175, -0.1, 0) * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(90), 0)
  125. Weld:Destroy()
  126. Shoulder.Part1 = LArm
  127. Shoulder.C1 = LeftShoulderMotor
  128. DataY = 0
  129. Use = false
  130. Busy = false
  131. end
  132. end
  133. elseif Key == "r" then
  134. if Up == false and Down == false and Use == true and Busy == false then
  135. Up = true
  136. while Up == true and DataY < 30 do
  137. DataY = DataY + 1
  138. Weld.C0 = Weld.C0 * CFrame.new(0, 0, -0.04) * CFrame.fromEulerAnglesXYZ(math.rad(3),math.rad(-1),math.rad(0))
  139. if ShieldWeld ~= nil then
  140. ShieldWeld.C0 = ShieldWeld.C0 * CFrame.new(-.02, 0, -.015) * CFrame.fromEulerAnglesXYZ(math.rad(-.9), math.rad(2), math.rad(-.75)) -- SHIELD WELD HERE
  141. end
  142. wait()
  143. end
  144. end
  145. elseif Key == "f" then
  146. if Down == false and Up == false and Use == true and Busy == false then
  147. Down = true
  148. while Down == true and DataY > 0 do
  149. DataY = DataY-1
  150. Weld.C0 = Weld.C0 * CFrame.new(0, 0, 0.04) * CFrame.fromEulerAnglesXYZ(math.rad(-3),math.rad(1),math.rad(0))
  151. if ShieldWeld ~= nil then
  152. ShieldWeld.C0 = ShieldWeld.C0 * CFrame.new(.02, 0, .015) * CFrame.fromEulerAnglesXYZ(math.rad(.9), math.rad(-2), math.rad(.75)) -- SHIELD WELD HERE
  153. end
  154. wait()
  155. end
  156. end
  157. end
  158. elseif Type == "Remove" then
  159. if Weld then
  160. Weld:Destroy()
  161. end
  162. Shoulder.Part1 = LArm
  163. if ShieldLink then
  164. ShieldLink:Destroy()
  165. end
  166. end
  167. end
  168.  
  169. function CommandStopped(Key)
  170. Key = Key:lower()
  171. if Key == "r" then
  172. Up = false
  173. elseif Key == "f" then
  174. Down = false
  175. end
  176. end
  177.  
  178. function RemoveFunction.OnClientInvoke()
  179. CommandIssued("Remove")
  180. end
  181.  
  182. print('cs top')
  183. CreateShield()
  184. print('creating shield')
  185.  
  186. Player:GetMouse().KeyDown:connect(function(Key)
  187. CommandIssued("KeyPress", Key)
  188. end)
  189.  
  190. Player:GetMouse().KeyUp:connect(CommandStopped)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement