MechaXYZ

Linked Sword Roblox

Oct 20th, 2021 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.10 KB | None | 0 0
  1. Tool0 = Instance.new("Tool")
  2. Part1 = Instance.new("Part")
  3. SpecialMesh2 = Instance.new("SpecialMesh")
  4. Tool0.Name = "Linked Sword"
  5. Tool0.ToolTip = "It slices, it dices. One click to slash, double click to lunge. Lunging does 3x damage."
  6. Tool0.Parent = owner.Backpack
  7. Tool0.Grip = CFrame.new(0, 0, -1.5) * CFrame.Angles(math.rad(90),math.rad(90),0)
  8. Tool0.TextureId = 'rbxasset://Textures/Sword128.png'
  9. Part1.Name = "Handle"
  10. Part1.Parent = Tool0
  11. Part1.Color = Color3.fromRGB(99, 95, 98)
  12. Part1.Reflectance = 0.4
  13. Part1.Size = Vector3.new(1, 0.8, 4)
  14. SpecialMesh2.Parent = Part1
  15. SpecialMesh2.MeshId = "rbxasset://fonts/sword.mesh"
  16. SpecialMesh2.Scale = Vector3.new(1,1,1)
  17. SpecialMesh2.TextureId = "rbxasset://textures/SwordTexture.png"
  18. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  19. Tool = Tool0
  20. Handle = Part1
  21.  
  22. function Create(ty)
  23. return function(data)
  24. local obj = Instance.new(ty)
  25. for k, v in pairs(data) do
  26. if type(k) == 'number' then
  27. v.Parent = obj
  28. else
  29. obj[k] = v
  30. end
  31. end
  32. return obj
  33. end
  34. end
  35.  
  36. local BaseUrl = "rbxassetid://"
  37.  
  38. Players = game:GetService("Players")
  39. Debris = game:GetService("Debris")
  40. RunService = game:GetService("RunService")
  41.  
  42. DamageValues = {
  43. BaseDamage = 5,
  44. SlashDamage = 10,
  45. LungeDamage = 30
  46. }
  47.  
  48. --For R15 avatars
  49. Animations = {
  50. R15Slash = 522635514,
  51. R15Lunge = 522638767
  52. }
  53.  
  54. Damage = DamageValues.BaseDamage
  55.  
  56. Grips = {
  57. Up = CFrame.new(0, 0, -1.70000005, 0, 0, 1, 1, 0, 0, 0, 1, 0),
  58. Out = CFrame.new(0, 0, -1.70000005, 0, 1, 0, 1, -0, 0, 0, 0, -1)
  59. }
  60. Slash = Instance.new("Sound" , owner.Character.Head)
  61. Slash.SoundId = 'rbxassetid://12222216'
  62. Slash.Name = 'SwordSlash'
  63. Lunge = Instance.new("Sound" , owner.Character.Head)
  64. Lunge.SoundId = 'rbxassetid://12222208'
  65. Lunge.Name = 'SwordLunge'
  66. Unsheath = Instance.new("Sound" , owner.Character.Head)
  67. Unsheath.SoundId = 'rbxassetid://12222225'
  68. Unsheath.Name = 'Unsheath'
  69. Sounds = {
  70. Slash = owner.Character.Head:WaitForChild("SwordSlash"),
  71. Lunge = owner.Character.Head:WaitForChild("SwordLunge"),
  72. Unsheath = owner.Character.Head:WaitForChild("Unsheath")
  73. }
  74.  
  75. ToolEquipped = false
  76.  
  77. --For Omega Rainbow Katana thumbnail to display a lot of particles.
  78. for i, v in pairs(Handle:GetChildren()) do
  79. if v:IsA("ParticleEmitter") then
  80. v.Rate = 20
  81. end
  82. end
  83.  
  84. Tool.Grip = Grips.Up
  85. Tool.Enabled = true
  86.  
  87. function IsTeamMate(Player1, Player2)
  88. return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
  89. end
  90.  
  91. function TagHumanoid(humanoid, player)
  92. local Creator_Tag = Instance.new("ObjectValue")
  93. Creator_Tag.Name = "creator"
  94. Creator_Tag.Value = player
  95. Debris:AddItem(Creator_Tag, 2)
  96. Creator_Tag.Parent = humanoid
  97. end
  98.  
  99. function UntagHumanoid(humanoid)
  100. for i, v in pairs(humanoid:GetChildren()) do
  101. if v:IsA("ObjectValue") and v.Name == "creator" then
  102. v:Destroy()
  103. end
  104. end
  105. end
  106.  
  107. function Blow(Hit)
  108. if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
  109. return
  110. end
  111. local RightArm = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand")
  112. if not RightArm then
  113. return
  114. end
  115. local RightGrip = RightArm:FindFirstChild("RightGrip")
  116. if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
  117. return
  118. end
  119. local character = Hit.Parent
  120. if character == Character then
  121. return
  122. end
  123. local humanoid = character:FindFirstChildOfClass("Humanoid")
  124. if not humanoid or humanoid.Health == 0 then
  125. return
  126. end
  127. local player = Players:GetPlayerFromCharacter(character)
  128. if player and (player == Player or IsTeamMate(Player, player)) then
  129. return
  130. end
  131. UntagHumanoid(humanoid)
  132. TagHumanoid(humanoid, Player)
  133. humanoid:TakeDamage(Damage)
  134. end
  135.  
  136.  
  137. function Attack()
  138. Damage = DamageValues.SlashDamage
  139. Sounds.Slash:Play()
  140.  
  141. if Humanoid then
  142. if Humanoid.RigType == Enum.HumanoidRigType.R6 then
  143. local Anim = Instance.new("StringValue")
  144. Anim.Name = "toolanim"
  145. Anim.Value = "Slash"
  146. Anim.Parent = Tool
  147. elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
  148. local Anim = Tool:FindFirstChild("R15Slash")
  149. if Anim then
  150. local Track = Humanoid:LoadAnimation(Anim)
  151. Track:Play(0)
  152. end
  153. end
  154. end
  155. end
  156.  
  157. function Lunge()
  158. Damage = DamageValues.LungeDamage
  159.  
  160. Sounds.Lunge:Play()
  161.  
  162. if Humanoid then
  163. if Humanoid.RigType == Enum.HumanoidRigType.R6 then
  164. local Anim = Instance.new("StringValue")
  165. Anim.Name = "toolanim"
  166. Anim.Value = "Lunge"
  167. Anim.Parent = Tool
  168. elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
  169. local Anim = Tool:FindFirstChild("R15Lunge")
  170. if Anim then
  171. local Track = Humanoid:LoadAnimation(Anim)
  172. Track:Play(0)
  173. end
  174. end
  175. end
  176. if CheckIfAlive() then
  177. local Force = Instance.new("BodyVelocity")
  178. Force.velocity = Vector3.new(0, 10, 0)
  179. Force.maxForce = Vector3.new(0, 4000, 0)
  180. Debris:AddItem(Force, 0.4)
  181. Force.Parent = Torso
  182. end
  183.  
  184. wait(0.2)
  185. Tool.Grip = Grips.Out
  186. wait(0.6)
  187. Tool.Grip = Grips.Up
  188.  
  189. Damage = DamageValues.SlashDamage
  190. end
  191.  
  192. Tool.Enabled = true
  193. LastAttack = 0
  194.  
  195. function Activated()
  196. if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
  197. return
  198. end
  199. Tool.Enabled = false
  200. local Tick = RunService.Stepped:wait()
  201. if (Tick - LastAttack < 0.2) then
  202. Lunge()
  203. else
  204. Attack()
  205. end
  206. LastAttack = Tick
  207. --wait(0.5)
  208. Damage = DamageValues.BaseDamage
  209. local SlashAnim = (Tool:FindFirstChild("R15Slash") or Create("Animation"){
  210. Name = "R15Slash",
  211. AnimationId = BaseUrl .. Animations.R15Slash,
  212. Parent = Tool
  213. })
  214.  
  215. local LungeAnim = (Tool:FindFirstChild("R15Lunge") or Create("Animation"){
  216. Name = "R15Lunge",
  217. AnimationId = BaseUrl .. Animations.R15Lunge,
  218. Parent = Tool
  219. })
  220. Tool.Enabled = true
  221. end
  222.  
  223. function CheckIfAlive()
  224. return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false)
  225. end
  226.  
  227. function Equipped()
  228. Character = Tool.Parent
  229. Player = Players:GetPlayerFromCharacter(Character)
  230. Humanoid = Character:FindFirstChildOfClass("Humanoid")
  231. Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("HumanoidRootPart")
  232. if not CheckIfAlive() then
  233. return
  234. end
  235. ToolEquipped = true
  236. Sounds.Unsheath:Play()
  237. end
  238.  
  239. function Unequipped()
  240. Tool.Grip = Grips.Up
  241. ToolEquipped = false
  242. end
  243.  
  244. Tool.Activated:Connect(Activated)
  245. Tool.Equipped:Connect(Equipped)
  246. Tool.Unequipped:Connect(Unequipped)
  247.  
  248. Connection = Handle.Touched:Connect(Blow)
  249. local ls = [[
  250.  
  251. Mouse_Icon = "rbxasset://textures/GunCursor.png"
  252. Reloading_Icon = "rbxasset://textures/GunWaitCursor.png"
  253.  
  254. Tool = game:GetService("Players").LocalPlayer.Backpack['Linked Sword'] or game:GetService("Players").LocalPlayer.Character['Linked Sword']
  255.  
  256. Mouse = nil
  257.  
  258. function UpdateIcon()
  259. if Mouse then
  260. Mouse.Icon = Tool.Enabled and Mouse_Icon or Reloading_Icon
  261. end
  262. end
  263.  
  264. function OnEquipped(ToolMouse)
  265. Mouse = ToolMouse
  266. UpdateIcon()
  267. end
  268.  
  269. function OnChanged(Property)
  270. if Property == "Enabled" then
  271. UpdateIcon()
  272. end
  273. end
  274.  
  275. Tool.Equipped:Connect(OnEquipped)
  276. Tool.Changed:Connect(OnChanged)
  277. ]]
  278. NLS(ls, owner.Character)
Add Comment
Please, Sign In to add comment