Advertisement
Guest User

lel

a guest
Jul 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. This code goes in a LocalScript inside StarterPlayerScripts
  2.  
  3. --// Services
  4. local UserInputService = game:GetService('UserInputService')
  5. local ReplicatedStorage = game:GetService('ReplicatedStorage')
  6. local Players = game:GetService('Players')
  7.  
  8. --// Debounces
  9. local Punching = false
  10. local Damaging = true
  11.  
  12. --// Customisation
  13. local Damage = inf
  14. local Cooldown = 0.2
  15.  
  16. --// Events
  17. local PunchEvent = ReplicatedStorage:WaitForChild('PunchEvent')
  18.  
  19. --// Player
  20. local Player = game.Players.LocalPlayer
  21. local Character = game.Workspace:WaitForChild(Player.Name)
  22. local Humanoid = Character:FindFirstChildOfClass('Humanoid')
  23. local RightArm = Character:WaitForChild('Right Arm')
  24.  
  25. --//Animations
  26. Punch = Instance.new('Animation')
  27. Punch.AnimationId = 'rbxassetid://953446258'
  28. PunchTrack = Humanoid:LoadAnimation(Punch)
  29.  
  30. --// Coding
  31. UserInputService.InputBegan:Connect(function(Input)
  32. if Input.KeyCode == Enum.KeyCode.E and not Punching then
  33. Punching = true
  34. PunchTrack:Play()
  35. PunchTrack.KeyframeReached:Connect(function(Keyframe)
  36. if Keyframe == 'End' then
  37. wait(Cooldown)
  38. Punching = false
  39. Damaging = true
  40. end
  41. end)
  42. end
  43. end)
  44.  
  45. RightArm.Touched:Connect(function(hitPart)
  46. if Punching and hitPart.Parent:FindFirstChild('Humanoid') and Damaging then
  47. Damaging = false
  48. local HumanoidToDamage = hitPart.Parent:FindFirstChild('Humanoid')
  49. PunchEvent:FireServer(HumanoidToDamage, Damage)
  50. end
  51. end)
  52.  
  53. This code goes inside a Script inside ServerScriptService
  54.  
  55. --// Services
  56. local ReplicatedStorage = game:GetService('ReplicatedStorage')
  57.  
  58. --// Events
  59. local PunchEvent = ReplicatedStorage:WaitForChild('PunchEvent')
  60.  
  61. --// Coding
  62. PunchEvent.OnServerEvent:Connect(function(PlayerWhoSent, HumanoidToDamage, Damage)
  63. HumanoidToDamage:TakeDamage(Damage)
  64. end)
  65.  
  66. Make sure you create a RemoteEvent called 'PunchEvent' and parent it to the ReplicatedStorage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement