Advertisement
Guest User

Untitled

a guest
Feb 8th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.19 KB | None | 0 0
  1. ~~~~~~~~~~~~~~~~~
  2. game.Players.PlayerAdded:connect(function(playerr)
  3. script.Parent.OnServerEvent:connect(function(plr,d)
  4. repeat wait() until plr.Character
  5. local character = plr.Character
  6. local mouse = d
  7. local tool = plr.Backpack.Lightsaber
  8. local ls = "LightSaberModel"
  9. -------------------------------------------------------------------------------------
  10. local poseanim = Instance.new("Animation")
  11. poseanim.AnimationId = "rbxassetid://579218292"
  12. local pose = character.Humanoid:LoadAnimation(poseanim)
  13.  
  14. local equipanim = Instance.new("Animation")
  15. equipanim.AnimationId = "rbxassetid://579218986"
  16. local equip = character.Humanoid:LoadAnimation(equipanim)
  17.  
  18. local block1anim = Instance.new("Animation")
  19. block1anim.AnimationId = "rbxassetid://579216931"
  20. local block1 = character.Humanoid:LoadAnimation(block1anim)
  21.  
  22. local stunanim = Instance.new("Animation")
  23. stunanim.AnimationId = "rbxassetid://579218986"
  24. local stun = character.Humanoid:LoadAnimation(stunanim)
  25. -------------------------------------------------------------------------------------
  26. local enabled = false
  27.  
  28. local active = false
  29. local activating = false
  30.  
  31. local attacking = false
  32. local canattack = false
  33. local candamage = false
  34. local jumping = false
  35. local forceactive = false
  36.  
  37. local blocking = false
  38. local canblock = false
  39.  
  40. local timer = 0
  41. local direction = 0
  42. local hitcounter = 0
  43. local stamina = 200
  44. -------------------------------------------------------------------------------------
  45. function UpdateStamina()
  46. if stamina <= 0 and character:FindFirstChild(ls) and active then
  47. attacking = false
  48. candamage = false
  49. canattack = false
  50. if character.Humanoid:FindFirstChild("Block") then
  51. character.Humanoid:FindFirstChild("Block"):Remove()
  52. end
  53. block1:Stop()
  54. local saber = character:FindFirstChild(ls)
  55. saber.Blade.CanClash.Value = false
  56. local sound = saber.Blade:FindFirstChild("slash")
  57. sound.Pitch = math.random(95,110)/100
  58. sound:Play()
  59. blocking = false
  60. canattack = true
  61. canblock = true
  62. end
  63. while (blocking == false and enabled and stamina < 200) and character:FindFirstChild(ls) do
  64. stamina = stamina + 2
  65. wait()
  66. end
  67. end
  68.  
  69. function WeldParts(b)
  70. local saber = game.Lighting:FindFirstChild(ls):Clone()
  71. saber.Parent = character
  72. local a = saber.Handle
  73. local w = Instance.new("Weld")
  74. w.Name = "SaberWeld"
  75. w.Parent = a
  76. w.Part0 = b
  77. w.Part1 = a
  78. w.C0 = CFrame.new(0,-1,0) * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(180),math.rad(180))
  79. end
  80.  
  81. function OnTouch(p)
  82. if candamage == true then
  83. local mySaber = character:FindFirstChild(ls)
  84. local theirSaber = p.Parent.Parent:FindFirstChild(ls)
  85. if (p.Name == "Blade" or p.Name == "Blade2") then
  86. if p:FindFirstChild("CanClash").Value == true then
  87. local function AddEffect(name,parent,duration)
  88. local effect = game.ReplicatedStorage[name]:Clone()
  89. effect.Parent = parent
  90. game.Debris:AddItem(effect,duration)
  91. end
  92. candamage = false
  93. local SoundList = {"hit1","hit2"}
  94. local sound = mySaber.Blade:FindFirstChild(SoundList[math.random(1,2)])
  95. sound.Pitch = math.random(90,110)/100
  96. sound:Play()
  97. AddEffect("Clash",mySaber.Blade,0.2)
  98. AddEffect("Sparks",theirSaber.Blade,0.75)
  99. AddEffect("ClashLight",theirSaber.Aura,0.4)
  100. if theirSaber:FindFirstChild("Blade2") then
  101. AddEffect("Sparks",theirSaber.Blade2,0.75)
  102. AddEffect("ClashLight",theirSaber.Aura2,0,4)
  103. end
  104. if theirSaber.Parent.Humanoid:FindFirstChild("Block") then
  105. theirSaber.Parent.Humanoid:FindFirstChild("Block"):Remove()
  106. local signal = Instance.new("ObjectValue")
  107. signal.Name = "ClashSignal"
  108. signal.Parent = theirSaber.Parent.Humanoid
  109. Stun()
  110. end
  111. end
  112. elseif p.Name == "Torso" and p.Parent:FindFirstChild("Humanoid") then
  113. candamage = false
  114. local hum = p.Parent:FindFirstChild("Humanoid")
  115. if not hum:FindFirstChild("Block") then
  116. hum:TakeDamage(21)
  117. local SoundList = {"hit1","hit2"}
  118. local sound = mySaber.Blade:FindFirstChild(SoundList[math.random(1,2)])
  119. sound.Pitch = math.random(90,110)/100
  120. sound:Play()
  121. elseif hum:FindFirstChild("Block") then
  122. hum:TakeDamage(0)
  123. end
  124. if not p.Parent:FindFirstChild(ls) then
  125. hum:TakeDamage(55)
  126. end
  127. elseif (p.Name == "Left Arm"
  128. or p.Name == "Right Arm"
  129. or p.Name == "Right Leg"
  130. or p.Name == "Left Leg"
  131. or p.Name == "Head")
  132. and p.Parent:FindFirstChild("Humanoid") then
  133. if p.Parent:FindFirstChild(ls) then
  134. local num = math.random(1,85)
  135. if num == 1 then
  136. candamage = false
  137. local hum = p.Parent:FindFirstChild("Humanoid")
  138. if not hum:FindFirstChild("Block") then
  139. hum:TakeDamage(21)
  140. local SoundList = {"hit1","hit2"}
  141. local sound = mySaber.Blade:FindFirstChild(SoundList[math.random(1,2)])
  142. sound.Pitch = math.random(90,110)/100
  143. sound:Play()
  144. p:BreakJoints()
  145. p.CanCollide = true
  146. p.Anchored = false
  147. local Sounds = {"rbxassetid://337800380","rbxassetid://337804646"}
  148. local s = Instance.new("Sound")
  149. s.Parent = p.Parent.Head
  150. s.SoundId = Sounds[math.random(1,2)]
  151. s.Volume = 1
  152. s.Pitch = 1
  153. s.Looped = false
  154. local w = Instance.new("Weld")
  155. w.Parent = mySaber.Aura
  156. w.Part0 = w.Parent
  157. w.Part1 = p
  158. game.Debris:AddItem(s,3)
  159. s:Play()
  160. game.Debris:AddItem(w,0.3)
  161. end
  162. end
  163. elseif not p.Parent:FindFirstChild(ls) then
  164. candamage = false
  165. local hum = p.Parent:FindFirstChild("Humanoid")
  166. if not hum:FindFirstChild("Block") then
  167. hum:TakeDamage(21)
  168. local SoundList = {"hit1","hit2"}
  169. local sound = mySaber.Blade:FindFirstChild(SoundList[math.random(1,2)])
  170. sound.Pitch = math.random(90,110)/100
  171. sound:Play()
  172. p:BreakJoints()
  173. p.CanCollide = true
  174. p.Anchored = false
  175. local Sounds = {"rbxassetid://337800380","rbxassetid://337804646"}
  176. local s = Instance.new("Sound")
  177. s.Parent = p.Parent.Head
  178. s.SoundId = Sounds[math.random(1,2)]
  179. s.Volume = 1
  180. s.Pitch = 1
  181. s.Looped = false
  182. local w = Instance.new("Weld")
  183. w.Parent = mySaber.Aura
  184. w.Part0 = w.Parent
  185. w.Part1 = p
  186. game.Debris:AddItem(s,3)
  187. s:Play()
  188. game.Debris:AddItem(w,0.3)
  189. end
  190. end
  191. end
  192.  
  193. end
  194. end
  195.  
  196. function Selected()
  197. enabled = true
  198. equip:Play(0.1,1,1.6)
  199. stamina = 200
  200. if not character:FindFirstChild(ls) then
  201. WeldParts(character["Right Arm"])
  202. end
  203. if character:FindFirstChild("HipSaber") then
  204. character:FindFirstChild("HipSaber"):Remove()
  205. end
  206. local saber = character:FindFirstChild(ls)
  207. saber.Handle.Equip:Play()
  208. saber.Aura.Glow.Color = tool.Glow.Value
  209. local c = saber.Emitter:GetChildren()
  210. for i = 1,#c do
  211. if c[i]:IsA("ParticleEmitter") then
  212. c[i].Color = ColorSequence.new(tool.Glow.Value,tool.Glow.Value)
  213. end
  214. end
  215. local c = saber.Aura:GetChildren()
  216. for i = 1,#c do
  217. if c[i]:IsA("ParticleEmitter") then
  218. c[i].Color = ColorSequence.new(tool.Glow.Value,tool.Glow.Value)
  219. end
  220.  
  221. character:FindFirstChild(ls).Blade.Touched:connect(OnTouch)end
  222. mouse.Button2Up:connect(Button2Up)
  223. end
  224.  
  225. function Deselected()
  226. if active == true then
  227. character[ls].Handle.sheathe:Play()
  228. end
  229. stamina = 200
  230. character.Humanoid.WalkSpeed = 16
  231. enabled = false
  232. active = false
  233. attacking = false
  234. canattack = false
  235. candamage = false
  236. blocking = false
  237. canblock = false
  238. blocking = false
  239. pose:Stop()
  240. block1:Stop()
  241. if character:FindFirstChild(ls) then
  242. character[ls]:Remove()
  243. end
  244. if character.Humanoid:FindFirstChild("Block") then
  245. character.Humanoid:FindFirstChild("Block"):Remove()
  246. end
  247. if not character:FindFirstChild("HipSaber") then
  248. local hilt = game.Lighting.LightSaberModel:Clone()
  249. hilt.Parent = character
  250. hilt.Name = "HipSaber"
  251. local a = hilt.Handle
  252. local w = Instance.new("Weld")
  253. w.Name = "Weld"
  254. w.Parent = a
  255. w.Part0 = character["Torso"]
  256. w.Part1 = a
  257. w.C0 = CFrame.new(-0.8,-1,-0.6) * CFrame.fromEulerAnglesXYZ(math.rad(180),math.rad(180),math.rad(-5))
  258. end
  259. end
  260.  
  261. mouse.Button1Down:connect(function()
  262. local SwingSounds = {"slash","slash2"}
  263. if (enabled and active) and canattack and blocking == false and forceactive == false then
  264. local saber = character:FindFirstChild(ls)
  265. if saber.Blade.CanClash.Value == false then
  266. coroutine.resume(coroutine.create(function()
  267. local c = saber.Blade:GetChildren()
  268. for n = 1,#c do
  269. if c[n]:IsA("ParticleEmitter") then
  270. c[n].Color = ColorSequence.new(tool.Glow.Value,tool.Glow.Value)
  271. c[n].Enabled = true
  272. end
  273. end
  274. end))
  275. attacking = true
  276. canblock = false
  277. canattack = false
  278. local sound = saber.Blade:FindFirstChild(SwingSounds[math.random(1,2)])
  279. sound.Pitch = math.random(100,110)/100
  280. sound:Play()
  281. local function GetAnimation()
  282. local slashanims = {"Attack1","Attack2"}
  283. if hitcounter == 0 then
  284. timer = tick()
  285. hitcounter = 1
  286. return slashanims[1]
  287. elseif hitcounter == 1 then
  288. if (tick() - timer) > 1 then
  289. timer = tick()
  290. hitcounter = 1
  291. return slashanims[1]
  292. elseif (tick() - timer) < 1 then
  293. hitcounter = 0
  294. return slashanims[2]
  295. end
  296. end
  297. end
  298. local track = GetAnimation()
  299. local slash = character.Humanoid:LoadAnimation(tool[track])
  300. slash:Play(0.1,1,1.7)
  301. candamage = true
  302. saber.Blade.CanClash.Value = true
  303. character.Humanoid.WalkSpeed = 22
  304. wait(0.6)
  305. coroutine.resume(coroutine.create(function()
  306. local c = saber.Blade:GetChildren()
  307. for n = 1,#c do
  308. if c[n]:IsA("ParticleEmitter") then
  309. c[n].Color = ColorSequence.new(tool.Glow.Value,tool.Glow.Value)
  310. c[n].Enabled = false
  311. end
  312. end
  313. end))
  314. candamage = false
  315. character.Humanoid.WalkSpeed = 16
  316. saber.Blade.CanClash.Value = false
  317. wait(0.15)
  318. attacking = false
  319. canattack = true
  320. canblock = true
  321. end
  322. end
  323. end)
  324.  
  325. mouse.Button2Down:connect(function()
  326. if (enabled and active and stamina > 0) and canblock == true and forceactive == false then
  327. blocking = true
  328. if not character.Humanoid:FindFirstChild("Block") then
  329. local blocker = Instance.new("ObjectValue")
  330. blocker.Name = "Block"
  331. blocker.Parent = character.Humanoid
  332. end
  333. attacking = false
  334. candamage = false
  335. canattack = false
  336. block1:Play()
  337. local saber = character:FindFirstChild(ls)
  338. saber.Blade.CanClash.Value = true
  339. local sound = saber.Blade:FindFirstChild("slash")
  340. sound.Pitch = math.random(95,110)/100
  341. sound:Play()
  342. Blocking()
  343. elseif (enabled and active and stamina > 0) and attacking and forceactive == false then
  344. blocking = true
  345. canblock = true
  346. if not character.Humanoid:FindFirstChild("Block") then
  347. local blocker = Instance.new("ObjectValue")
  348. blocker.Name = "Block"
  349. blocker.Parent = character.Humanoid
  350. end
  351. attacking = false
  352. canattack = false
  353. block1:Play()
  354. local saber = character:FindFirstChild(ls)
  355. saber.Blade.CanClash.Value = true
  356. local sound = saber.Blade:FindFirstChild("slash")
  357. sound.Pitch = math.random(95,110)/100
  358. sound:Play()
  359. Blocking()
  360. end
  361. end)
  362.  
  363. function Button2Up()
  364. if enabled and active and blocking and forceactive == false then
  365. if character.Humanoid:FindFirstChild("Block") then
  366. character.Humanoid:FindFirstChild("Block"):Remove()
  367. end
  368. block1:Stop()
  369. local saber = character:FindFirstChild(ls)
  370. saber.Blade.CanClash.Value = false
  371. local sound = saber.Blade:FindFirstChild("slash")
  372. sound.Pitch = math.random(95,110)/100
  373. sound:Play()
  374. wait()
  375. canattack = true
  376. canblock = true
  377. blocking = false
  378. coroutine.resume(coroutine.create(UpdateStamina))
  379. end
  380. end
  381.  
  382. function Stun()
  383. local saber = character:FindFirstChild(ls)
  384. pose:Stop()
  385. block1:Stop()
  386. stun:Play(0.5,1,1)
  387. character.Humanoid.WalkSpeed = 0
  388. character.Humanoid.JumpPower = 0
  389. if character.Humanoid:FindFirstChild("Block") then
  390. character.Humanoid:FindFirstChild("Block"):Remove()
  391. end
  392. enabled = false
  393. attacking = false
  394. canattack = false
  395. candamage = false
  396. blocking = false
  397. canblock = false
  398. blocking = false
  399. jumping = true
  400. wait(0.75)
  401. character.Humanoid.WalkSpeed = 16
  402. character.Humanoid.JumpPower = 50
  403. stun:Stop()
  404. pose:Play()
  405. jumping = false
  406. enabled = true
  407. canattack = true
  408. canblock = true
  409. end
  410.  
  411. function BladeUp()
  412. local saber = character:findFirstChild(ls)
  413. saber.Emitter.EmitterWeld.C0 = CFrame.new(0,0,0)
  414. local c = saber.Emitter:GetChildren()
  415. for i = 1,#c do
  416. if c[i]:IsA("ParticleEmitter") then
  417. c[i].Enabled = true
  418. end
  419. end
  420. saber.Aura.Transparency = 0.01
  421. local m = Instance.new("CylinderMesh")
  422. m.Parent = saber.Aura
  423. m.Scale = Vector3.new(1,0,1)
  424. m.Offset = Vector3.new(0,-2.05,0)
  425. local x = 15
  426. for i = 1,x do
  427. m.Scale = m.Scale + Vector3.new(0,1/x,0)
  428. m.Offset = m.Offset + Vector3.new(0,2.05/x)
  429. wait()
  430. end
  431. m:Destroy()
  432. local c = saber.Aura:GetChildren()
  433. for i = 1,#c do
  434. if c[i]:IsA("ParticleEmitter") then
  435. c[i].Transparency = NumberSequence.new(0.95)
  436. end
  437. end
  438. end
  439.  
  440. function BladeDown()
  441. local saber = character:findFirstChild(ls)
  442. saber.Emitter.EmitterWeld.C0 = CFrame.new(0,4.15,0)*CFrame.fromEulerAnglesXYZ(0,0,math.rad(180))
  443. wait(0.2)
  444. local m = Instance.new("CylinderMesh")
  445. m.Parent = saber.Aura
  446. m.Scale = Vector3.new(1,1,1)
  447. m.Offset = Vector3.new(0,0,0)
  448. local c = saber.Emitter:GetChildren()
  449. for i = 1,#c do
  450. if c[i]:IsA("ParticleEmitter") then
  451. c[i].Enabled = false
  452. end
  453. end
  454. local c = saber.Aura:GetChildren()
  455. for i = 1,#c do
  456. if c[i]:IsA("ParticleEmitter") then
  457. c[i].Transparency = NumberSequence.new(1)
  458. end
  459. end
  460. local x = 13
  461. for i = 1,x do
  462. m.Scale = m.Scale - Vector3.new(0,1/x,0)
  463. m.Offset = m.Offset - Vector3.new(0,2.05/x)
  464. wait()
  465. end
  466. m:Destroy()
  467. saber.Aura.Transparency = 1
  468. end
  469.  
  470. mouse.KeyDown:connect(function(key)
  471. --Toggling
  472. local saber = character:FindFirstChild(ls)
  473. if key == "q" and enabled then
  474. if active == false and activating == false and not blocking and not attacking then
  475. activating = true
  476. active = true
  477. pose:Play()
  478. wait(0.2)
  479. saber.Aura.Glow.Enabled = true
  480. saber.Handle.ignite:Play()
  481. saber.Handle.loop:Play()
  482. attacking = false
  483. canattack = true
  484. candamage = false
  485. blocking = false
  486. canblock = true
  487. BladeUp()
  488. activating = false
  489. elseif active == true and activating == false and not blocking and not attacking then
  490. activating = true
  491. active = false
  492. saber.Handle.sheathe:Play()
  493. BladeDown()
  494. saber.Aura.Glow.Enabled = false
  495. saber.Handle.loop:Pause()
  496. wait(0.2)
  497. pose:Stop()
  498. block1:Stop()
  499. activating = false
  500. attacking = false
  501. canattack = false
  502. candamage = false
  503. blocking = false
  504. canblock = false
  505. if character.Humanoid:FindFirstChild("Block") then
  506. character.Humanoid:FindFirstChild("Block"):Remove()
  507. end
  508. end
  509. --Flips
  510. elseif (key == "2"
  511. and jumping == false
  512. and blocking == false
  513. and direction ~= 0) then
  514. local function Flip()
  515. local flips = {579217547,0,579216033,0}
  516. local fliptrack = Instance.new("Animation")
  517. fliptrack.AnimationId = "rbxassetid://"..flips[direction]
  518. local flip = character.Humanoid:LoadAnimation(fliptrack)
  519. character.Humanoid.JumpPower = 65
  520. character.Humanoid.Jump = true
  521. character.Humanoid.WalkSpeed = 40
  522. stun:Stop()
  523. flip:Play(0.1,1,1.3)
  524. jumping = true
  525. canblock = false
  526. candamage = false
  527. attacking = false
  528. wait(0.4)
  529. character.Humanoid.WalkSpeed = 16
  530. character.Humanoid.JumpPower = 50
  531. canblock = true
  532. wait(0.7)
  533. jumping = false
  534. end
  535. if direction == 1 or direction == 3 then
  536. Flip()
  537. end
  538. elseif key == "w" then
  539. direction = 1
  540. elseif key == "s" then
  541. direction = 3
  542. --Force
  543. elseif key == "f" and enabled and activating == false then
  544. if (attacking == false and blocking == false and stamina >= 170 and character.Torso:FindFirstChild("Left Shoulder"))
  545. and plr.Backpack:FindFirstChild("HasForce").Value == true then
  546. forceactive = true
  547. canblock = false
  548. canattack = false
  549. stamina = stamina - 170
  550. local pushtrack = Instance.new("Animation")
  551. pushtrack.AnimationId = "rbxassetid://365857748"
  552. local push = character.Humanoid:LoadAnimation(pushtrack)
  553. push:Play()
  554. local p = Instance.new("Part")
  555. p.Parent = game.Workspace
  556. p.CanCollide = false
  557. p.formFactor = "Symmetric"
  558. p.Shape = "Block"
  559. p.Size = Vector3.new(1,1,1)
  560. p.Transparency = 1
  561. p.Material = "Neon"
  562. game.Debris:AddItem(p,1)
  563. local handlepos = character["Left Arm"].CFrame
  564. local firingPoint = handlepos.p + handlepos:vectorToWorldSpace(Vector3.new(0, 0.4, -1.3))
  565. local shotCFrame = CFrame.new(firingPoint, character.Humanoid.TargetPoint)
  566. p.CFrame = shotCFrame + (shotCFrame.lookVector * (p.Size.Z / 2))
  567. local bodyVelocity = Instance.new('BodyVelocity')
  568. bodyVelocity.velocity = shotCFrame.lookVector * 300
  569. bodyVelocity.Parent = p
  570. local victim = nil
  571. p.Touched:connect(function(p)
  572. if p.Parent ~= character and p.Parent:FindFirstChild("Humanoid") then
  573. victim = p.Parent
  574. local hum = p.Parent:FindFirstChild("Humanoid")
  575. hum.Sit = true
  576. local PushBack = CFrame.new(p.Position, character.Torso.Position).lookVector * -80
  577. PushBack = Vector3.new(PushBack.X, -80, PushBack.Z)
  578. p.Velocity = PushBack
  579. local signal = Instance.new("ObjectValue")
  580. signal.Name = "ClashSignal"
  581. signal.Parent = hum
  582. end
  583. end)
  584. wait(0.4)
  585. forceactive = false
  586. if active then
  587. canblock = true
  588. canattack = true
  589. end
  590. coroutine.resume(coroutine.create(UpdateStamina))
  591. end
  592. end
  593. end)
  594.  
  595. character.Humanoid.Running:connect(function(speed)
  596. if speed <= 0 then
  597. direction = 0
  598. end
  599. end)
  600.  
  601. character.Humanoid.ChildAdded:connect(function(item)
  602. if item.Name == "Block" then
  603. local saber = character:FindFirstChild(ls)
  604. saber.Blade.CanClash.Value = true
  605. blocking = true
  606. canblock = true
  607. Blocking()
  608. elseif item.Name == "ClashSignal" then
  609. stamina = 0
  610. coroutine.resume(coroutine.create(UpdateStamina))
  611. Button2Up()
  612. item:Destroy()
  613. end
  614. end)
  615.  
  616. function Blocking()
  617. while (blocking and canblock) and stamina > 0 do
  618. canattack = false
  619. candamage = false
  620. attacking = false
  621. stamina = stamina - 1
  622. coroutine.resume(coroutine.create(UpdateStamina))
  623. wait()
  624. end
  625. end
  626. tool.Equipped:connect(Selected)
  627. tool.Unequipped:connect(Deselected)
  628. end)
  629. end)
  630. ~~~~~~~~~~~~~~~~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement