ttvmetroidd

punch client

Jun 20th, 2024
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. local repstorage = game:GetService("ReplicatedStorage")
  2. local plrs = game:GetService("Players")
  3.  
  4. local plr = plrs.LocalPlayer
  5.  
  6. local tool = script.Parent
  7. local camera = workspace.CurrentCamera
  8. local events = repstorage:WaitForChild("Events")
  9.  
  10. local cameraShaker = require(repstorage:WaitForChild("Modules"):WaitForChild("Utilities"):WaitForChild("CameraShaker"))
  11.  
  12. local punchHoldAnim = nil
  13. local punchAnim = nil
  14.  
  15. local debounce = false
  16. local equipped = false
  17.  
  18. local camShake = cameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
  19. camera.CFrame = camera.CFrame * shakeCf
  20. end)
  21.  
  22. tool.Equipped:Connect(function()
  23. local character = plr.Character
  24. if character == nil then
  25. return
  26. end
  27. equipped = true
  28. local humanoid = character:FindFirstChild("Humanoid")
  29. if humanoid == nil then
  30. return
  31. end
  32. local animator = humanoid:FindFirstChild("Animator")
  33. if animator == nil then
  34. return
  35. end
  36. punchHoldAnim = animator:LoadAnimation(tool.Animations.PunchHold)
  37. punchHoldAnim:Play()
  38. end)
  39.  
  40. tool.Unequipped:Connect(function()
  41. equipped = false
  42. if punchHoldAnim == nil then
  43. return
  44. end
  45. punchHoldAnim:Stop()
  46. end)
  47.  
  48. tool.Activated:Connect(function()
  49. if debounce then
  50. return
  51. end
  52. local character = plr.Character
  53. if character == nil then
  54. return
  55. end
  56. if punchHoldAnim ~= nil then
  57. punchHoldAnim:Stop()
  58. end
  59. debounce = true
  60. local humanoid = character:FindFirstChild("Humanoid")
  61. if humanoid == nil then
  62. return
  63. end
  64. local animator = humanoid:FindFirstChild("Animator")
  65. if animator == nil then
  66. return
  67. end
  68.  
  69. local punchClickAnim = animator:LoadAnimation(tool.Animations.PunchClick)
  70. punchClickAnim:Play()
  71.  
  72. punchClickAnim.KeyframeReached:Connect(function(keyframeName)
  73. camShake:Shake(cameraShaker.Presets.Bump)
  74. events.Punch:FireServer(25)
  75. end)
  76.  
  77.  
  78. punchClickAnim.Stopped:Connect(function()
  79. if punchHoldAnim ~= nil and equipped then
  80. punchHoldAnim:Play()
  81. end
  82. debounce = false
  83. end)
  84. end)
Advertisement
Add Comment
Please, Sign In to add comment