Advertisement
Guest User

Combat System Client Side (Local Script)

a guest
Jun 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2. local char = plr.Character or plr.CharacterAdded:Wait()
  3.  
  4. local replicatedStorage = game.ReplicatedStorage
  5.  
  6. local combatEvent = replicatedStorage.RemoteEventStorage:WaitForChild("combatEvent")
  7. local swordCombatEvent = replicatedStorage.RemoteEventStorage:WaitForChild("swordCombatEvent")
  8. local swordDrawEvent = replicatedStorage.RemoteEventStorage:WaitForChild("swordDrawEvent")
  9. local swordSheathEvent = replicatedStorage.RemoteEventStorage:WaitForChild("swordSheathEvent")
  10. local damageCombatEvent = replicatedStorage.RemoteEventStorage:WaitForChild("damageCombatEvent")
  11.  
  12. local combatDebounce = false
  13. local qDebounce = false
  14.  
  15. local swordCombatNum = 1
  16. local handCombatNum = 1
  17.  
  18. game:GetService("UserInputService").InputBegan:connect(function(key, isTyping)
  19. if isTyping then return end
  20.  
  21. if key.UserInputType == Enum.UserInputType.MouseButton1 then
  22. if combatDebounce == false and qDebounce == false then
  23. combatDebounce = true
  24.  
  25. if char.Equipped.Value == "Hands" then
  26. local hitbox = combatEvent:InvokeServer(handCombatNum)
  27. handCombatNum = handCombatNum + 1
  28. if handCombatNum == 4 then
  29. handCombatNum = 1
  30. end
  31. ----
  32. hitDebounce = false
  33. hitbox.Touched:connect(function(hit)
  34. if hitDebounce == false then
  35. if hit.Parent then
  36. local hitChar = hit.Parent
  37. if hitChar ~= char then
  38. local hitHuman = hitChar:FindFirstChild("Humanoid")
  39. if hitHuman then
  40. hitDebounce = true
  41. print("Contact")
  42.  
  43. local hitPlr = game.Players:GetPlayerFromCharacter(hitChar)
  44. if hitPlr then
  45. print("Player")
  46. damageCombatEvent:FireServer(hitChar, 20)
  47. else
  48. print("NPC")
  49. damageCombatEvent:FireServer(hitChar, 20)
  50. end
  51. end
  52. end
  53. end
  54. end
  55. end)
  56. ----
  57. wait(1)
  58.  
  59. elseif char.Equipped.Value == "Sword" then
  60. --Anim Choose Stuff Here
  61. local hitbox = swordCombatEvent:InvokeServer(1)
  62. ----
  63. hitDebounce = false
  64. hitbox.Touched:connect(function(hit)
  65. if hitDebounce == false then
  66. if hit.Parent then
  67. local hitChar = hit.Parent
  68. if hitChar ~= char then
  69. local hitHuman = hitChar:FindFirstChild("Humanoid")
  70. if hitHuman then
  71. hitDebounce = true
  72. print("Contact")
  73.  
  74. local hitPlr = game.Players:GetPlayerFromCharacter(hitChar)
  75. if hitPlr then
  76. print("Player")
  77. damageCombatEvent:FireServer(hitChar, 25)
  78. else
  79. print("NPC")
  80. damageCombatEvent:FireServer(hitChar, 25)
  81. end
  82. end
  83. end
  84. end
  85. end
  86. end)
  87. ----
  88. wait(1)
  89. end
  90. combatDebounce = false
  91. end
  92.  
  93. --[[elseif key.KeyCode == Enum.KeyCode.Q then
  94. if qDebounce == false then
  95. qDebounce = true
  96.  
  97. if char.Equipped.Value == "Hands" then
  98. swordDrawEvent:FireServer()
  99. elseif char.Equipped.Value == "Sword" then
  100. swordSheathEvent:FireServer()
  101. end
  102.  
  103. wait(1)
  104. qDebounce = false
  105. end]]
  106. end
  107. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement