hawoody

One Hit Sword

Apr 14th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Converted with ttyyuu12345's model to script plugin v4
  2. function sandbox(var,func)
  3. local env = getfenv(func)
  4. local newenv = setmetatable({},{
  5. __index = function(self,k)
  6. if k=="script" then
  7. return var
  8. else
  9. return env[k]
  10. end
  11. end,
  12. })
  13. setfenv(func,newenv)
  14. return func
  15. end
  16. cors = {}
  17. mas = Instance.new("Model",game:GetService("Lighting"))
  18. Tool0 = Instance.new("Tool")
  19. Script1 = Instance.new("Script")
  20. Part2 = Instance.new("Part")
  21. SpecialMesh3 = Instance.new("SpecialMesh")
  22. Sound4 = Instance.new("Sound")
  23. Sound5 = Instance.new("Sound")
  24. Sound6 = Instance.new("Sound")
  25. LocalScript7 = Instance.new("LocalScript")
  26. Tool0.Name = "ShiningSword"
  27. Tool0.Parent = mas
  28. Tool0.TextureId = "rbxasset://Textures/Sword128.png"
  29. Tool0.GripForward = Vector3.new(-1, -0, -0)
  30. Tool0.GripPos = Vector3.new(0, 0, -1.5)
  31. Tool0.GripRight = Vector3.new(0, 1, 0)
  32. Tool0.GripUp = Vector3.new(0, 0, 1)
  33. Script1.Name = "SwordScript"
  34. Script1.Parent = Tool0
  35. table.insert(cors,sandbox(Script1,function()
  36. r = game:service("RunService")
  37.  
  38.  
  39. local damage = math.huge
  40.  
  41.  
  42. local slash_damage = math.huge
  43. local lunge_damage = math.huge
  44.  
  45. sword = script.Parent.Handle
  46. Tool = script.Parent
  47.  
  48.  
  49. local SlashSound = Instance.new("Sound")
  50. SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav"
  51. SlashSound.Parent = sword
  52. SlashSound.Volume = .7
  53.  
  54. local LungeSound = Instance.new("Sound")
  55. LungeSound.SoundId = "rbxasset://sounds\\swordlunge.wav"
  56. LungeSound.Parent = sword
  57. LungeSound.Volume = .6
  58.  
  59. local UnsheathSound = Instance.new("Sound")
  60. UnsheathSound.SoundId = "rbxasset://sounds\\unsheath.wav"
  61. UnsheathSound.Parent = sword
  62. UnsheathSound.Volume = 1
  63.  
  64.  
  65. function blow(hit)
  66. if (hit.Parent == nil) then return end -- happens when bullet hits sword
  67.  
  68. local humanoid = hit.Parent:findFirstChild("Humanoid")
  69. local vCharacter = Tool.Parent
  70. local vPlayer = game.Players:playerFromCharacter(vCharacter)
  71. local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
  72. if humanoid~=nil and humanoid ~= hum and hum ~= nil then
  73. -- final check, make sure sword is in-hand
  74.  
  75. local right_arm = vCharacter:FindFirstChild("Right Arm")
  76. if (right_arm ~= nil) then
  77. local joint = right_arm:FindFirstChild("RightGrip")
  78. if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
  79. tagHumanoid(humanoid, vPlayer)
  80. humanoid:TakeDamage(damage)
  81. wait(1)
  82. untagHumanoid(humanoid)
  83. end
  84. end
  85.  
  86.  
  87. end
  88. end
  89.  
  90.  
  91. function tagHumanoid(humanoid, player)
  92. local creator_tag = Instance.new("ObjectValue")
  93. creator_tag.Value = player
  94. creator_tag.Name = "creator"
  95. creator_tag.Parent = humanoid
  96. end
  97.  
  98. function untagHumanoid(humanoid)
  99. if humanoid ~= nil then
  100. local tag = humanoid:findFirstChild("creator")
  101. if tag ~= nil then
  102. tag.Parent = nil
  103. end
  104. end
  105. end
  106.  
  107.  
  108. function attack()
  109. damage = slash_damage
  110. SlashSound:play()
  111. local anim = Instance.new("StringValue")
  112. anim.Name = "toolanim"
  113. anim.Value = "Slash"
  114. anim.Parent = Tool
  115. end
  116.  
  117. function lunge()
  118. damage = lunge_damage
  119.  
  120. LungeSound:play()
  121.  
  122. local anim = Instance.new("StringValue")
  123. anim.Name = "toolanim"
  124. anim.Value = "Lunge"
  125. anim.Parent = Tool
  126.  
  127.  
  128. force = Instance.new("BodyVelocity")
  129. force.velocity = Vector3.new(0,10,0) --Tool.Parent.Torso.CFrame.lookVector * 80
  130. force.Parent = Tool.Parent.Torso
  131. wait(.25)
  132. swordOut()
  133. wait(.25)
  134. force.Parent = nil
  135. wait(.5)
  136. swordUp()
  137.  
  138. damage = slash_damage
  139. end
  140.  
  141. function swordUp()
  142. Tool.GripForward = Vector3.new(-1,0,0)
  143. Tool.GripRight = Vector3.new(0,1,0)
  144. Tool.GripUp = Vector3.new(0,0,1)
  145. end
  146.  
  147. function swordOut()
  148. Tool.GripForward = Vector3.new(0,0,1)
  149. Tool.GripRight = Vector3.new(0,-1,0)
  150. Tool.GripUp = Vector3.new(-1,0,0)
  151. end
  152.  
  153. function swordAcross()
  154. -- parry
  155. end
  156.  
  157.  
  158. Tool.Enabled = true
  159. local last_attack = 0
  160. function onActivated()
  161.  
  162. if not Tool.Enabled then
  163. return
  164. end
  165.  
  166. Tool.Enabled = false
  167.  
  168. local character = Tool.Parent;
  169. local humanoid = character.Humanoid
  170. if humanoid == nil then
  171. print("Humanoid not found")
  172. return
  173. end
  174.  
  175. t = r.Stepped:wait()
  176.  
  177. if (t - last_attack < .2) then
  178. lunge()
  179. else
  180. attack()
  181. end
  182.  
  183. last_attack = t
  184.  
  185. --wait(.5)
  186.  
  187. Tool.Enabled = true
  188. end
  189.  
  190.  
  191. function onEquipped()
  192. UnsheathSound:play()
  193. end
  194.  
  195.  
  196. script.Parent.Activated:connect(onActivated)
  197. script.Parent.Equipped:connect(onEquipped)
  198.  
  199.  
  200. connection = sword.Touched:connect(blow)
  201.  
  202.  
  203.  
  204. end))
  205. Part2.Name = "Handle"
  206. Part2.Parent = Tool0
  207. Part2.BrickColor = BrickColor.new("Dark stone grey")
  208. Part2.Reflectance = 0.40000000596046
  209. Part2.Rotation = Vector3.new(-90, 0, -90)
  210. Part2.FormFactor = Enum.FormFactor.Plate
  211. Part2.Size = Vector3.new(1, 0.800000012, 4)
  212. Part2.CFrame = CFrame.new(-6.099998, 2.00001097, -11.5, 0, 1, 0, 0, 0, 1, 1, 0, 0)
  213. Part2.BottomSurface = Enum.SurfaceType.Smooth
  214. Part2.TopSurface = Enum.SurfaceType.Smooth
  215. Part2.Color = Color3.new(0.388235, 0.372549, 0.384314)
  216. Part2.Position = Vector3.new(-6.099998, 2.00001097, -11.5)
  217. Part2.Orientation = Vector3.new(-90, -90, 0)
  218. Part2.Color = Color3.new(0.388235, 0.372549, 0.384314)
  219. SpecialMesh3.Parent = Part2
  220. SpecialMesh3.MeshId = "rbxasset://fonts/sword.mesh"
  221. SpecialMesh3.TextureId = "http://www.roblox.com/asset/?id=3583703"
  222. SpecialMesh3.MeshType = Enum.MeshType.FileMesh
  223. Sound4.Parent = Part2
  224. Sound4.SoundId = "rbxasset://sounds/swordslash.wav"
  225. Sound4.Volume = 0.69999998807907
  226. Sound5.Parent = Part2
  227. Sound5.SoundId = "rbxasset://sounds/swordlunge.wav"
  228. Sound5.Volume = 0.60000002384186
  229. Sound6.Parent = Part2
  230. Sound6.SoundId = "rbxasset://sounds/unsheath.wav"
  231. Sound6.Volume = 1
  232. LocalScript7.Name = "Local Gui"
  233. LocalScript7.Parent = Tool0
  234. for i,v in pairs(mas:GetChildren()) do
  235. v.Parent = game:GetService("Players").LocalPlayer.Backpack
  236. pcall(function() v:MakeJoints() end)
  237. end
  238. mas:Destroy()
  239. for i,v in pairs(cors) do
  240. spawn(function()
  241. pcall(v)
  242. end)
  243. end
Add Comment
Please, Sign In to add comment