Advertisement
g14ndev

Heavy Sword Event Listener

Mar 23rd, 2024 (edited)
169
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.67 KB | Gaming | 0 0
  1. --- author : Gixnly
  2. -- **THIS SCRIPT IS AN EVENT LISTENER FOR A SWORD**
  3. --- the formatting looks off cause of the way pastebin formats it, i dont actually format my code like how pastebin shows --
  4.  
  5. local HeavySword  = script.Parent.Parent
  6. local remotes = script.Parent.Parent.Remotes
  7. local modules = game.ServerStorage.Modules
  8. local AttackPhysics = require(modules:WaitForChild("AttackPhysics"))
  9. local combatDuration = 5
  10. local debris = game:GetService("Debris")
  11. local damage = 30
  12. local specialDamage = 80
  13. local blockStunTime = 2
  14. local stunTime = 0.8
  15. local ragTime = 2 -- timer
  16. local perfectBlockTime = 0.25
  17. local reTime = 5
  18. local recentHit = {}
  19. local bloodVFX = game.ReplicatedStorage:WaitForChild("VFX"):WaitForChild("BIO"):WaitForChild("E - Gushing") -- vfx
  20.  
  21.  
  22. local falseConditionsTable = {
  23.     -- returns if the condition is true or false
  24.     function(target) return target.Parent:GetAttribute("IFrame") == false end
  25.  
  26. }
  27.  
  28. local trueConditionsTable = {
  29.     function(target) return target.Parent:GetAttribute("Player") == true end
  30. }
  31.  
  32. local function FalseConditions(conditions,target) -- checks if any of the conditions here return false  if it is false return true
  33.     for index, conditionFunc in ipairs(conditions) do
  34.         if not conditionFunc(target) then
  35.             print(index.." not met")
  36.             return true
  37.         end
  38.     end
  39.     return false
  40. end
  41.  
  42. local function TrueConditions(conditions,target) -- checks if any of the conditions here return false  if it is false return false
  43.     for index, conditionFunc in ipairs(conditions) do
  44.         if not conditionFunc(target) then
  45.             print(index.." not met")
  46.             return false
  47.         end
  48.     end
  49.     return true
  50. end
  51.  
  52.  
  53.  
  54.  
  55. remotes.ClientClickRemote.OnServerEvent:Connect(function(player,count,maxCombo) -- when a player clicks with the sword this fires
  56.  
  57.     local character = player.Character
  58.  
  59.  
  60.     if character then -- checking if the character isn't nil
  61.         character:SetAttribute("Attacking", true) -- pre defined attribute added in another script , used for checks
  62.         local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  63.  
  64.         -- Create the damage box
  65.         local damageBox = Instance.new("Part")
  66.  
  67.         damageBox.CanTouch = true
  68.         damageBox.Size = Vector3.new(5, 6, 5) -- Adjust the size as needed
  69.         damageBox.Anchored = false
  70.         damageBox.CanCollide = false
  71.         damageBox.Transparency = 0.5
  72.         damageBox.BrickColor = BrickColor.new("Bright red")
  73.  
  74.         damageBox.Name = "DamageBox"
  75.         damageBox.Parent = game.Workspace
  76.         damageBox.CFrame = humanoidRootPart.CFrame * CFrame.new(0,0,-2.5) -- Adjust the distance in front of the player      
  77.         damageBox.Touched:Connect(function(target)
  78.             if target.Parent == nil then return end -- checking if the target has a parent, and if target exists
  79.             if target == nil then return end
  80.  
  81.             local hum = target.Parent:FindFirstChildOfClass("Humanoid")
  82.  
  83.             if hum and count < maxCombo and FalseConditions(falseConditionsTable,target) == false and  TrueConditions(trueConditionsTable,target) == true then -- checks if the current combo position is less than the maximum combo
  84.  
  85.                 if target.Parent ~= player.Character and not table.find(recentHit, target.Parent) then
  86.                     local clone = bloodVFX.BloodVFX:Clone() -- create vfx
  87.                     clone.Parent = target.Parent:FindFirstChild("HumanoidRootPart") -- parent it to target
  88.                     task.delay(2,function() -- enable particle emitters
  89.                         for i, emitter in pairs(clone:GetDescendants()) do
  90.                             if emitter:IsA("ParticleEmitter") then
  91.                                 emitter.Enabled = false
  92.                             end
  93.                         end
  94.                         task.wait(0.5)
  95.                         clone:Destroy() -- destroy vfx after 0.5 seconds
  96.  
  97.                     end)
  98.                     character:SetAttribute("Combat", true)
  99.                     character:SetAttribute("CombatTimer", tick())  -- set attribute to tick, used to check if we can make combat false
  100.                     target.Parent:SetAttribute("Combat", true)
  101.                     target.Parent:SetAttribute("CombatTimer", tick()) -- same done for the target
  102.  
  103.                     if hum.Health - damage <= 0  and hum.Health > 0 and not table.find(recentHit, target.Parent) and target.Parent:GetAttribute("Blocking") == false then -- if the next hit would kill them and they're not dead and they're not in the debounce table and if they arent blocking
  104.  
  105.                         table.insert(recentHit, target.Parent) -- add them to the debounce (prevent multi hits)
  106.  
  107.  
  108.                         local gui = game.ReplicatedStorage.BillboardGui:Clone() -- clone a damage indicator gui
  109.                         debris:AddItem(gui,1)
  110.                         gui.Parent = target.Parent
  111.                         gui.DamageIndicate.Text = tostring(-damage)
  112.                         task.delay(task.wait(), function()
  113.                             for i = 0, 10 , .01 do
  114.                                 if gui == nil then return end
  115.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  116.                                 if gui:FindFirstChild("DamageIndicate") then
  117.                                     gui.DamageIndicate.TextTransparency += 0.05
  118.                                 end
  119.  
  120.                                 task.wait(0.01)
  121.                             end
  122.                         end)
  123.                         player.leaderstats.kills.Value +=1 -- add to player kills
  124.                         AttackPhysics.RagdollCharacter(target.Parent) -- ragdoll the target via a module function
  125.                         target.Parent:SetAttribute("RagTimer", tick()) -- set a timer for their ragdoll, (prevent bugs)
  126.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  127.                         hum:TakeDamage(damage)
  128.                         task.wait(reTime)
  129.                         table.remove(recentHit, table.find(recentHit, target.Parent)) -- remove from debounce after retime
  130.                         if target.Parent == nil then return end
  131.                         if tick() - target.Parent:GetAttribute("RagTimer") >= reTime then -- if they weren't ragdolled again then unragdoll them
  132.                             AttackPhysics.Unragdoll(target.Parent)
  133.                         end
  134.                         return --- returning to stop the rest of the code from running
  135.                     elseif hum.Health - damage <= 0  and hum.Health > 0 and not table.find(recentHit, target.Parent) and target.Parent:GetAttribute("Blocking") == true then -- if the next hit kills them but they were blocking
  136.                         if target.Parent:GetAttribute("PerfectBlock") == true then -- check if the perfect block attribute was true when hit landed
  137.                             local tarPlayer = game.Players:GetPlayerFromCharacter(target.Parent) -- try to find a player obj from the target
  138.                             if tarPlayer then
  139.                                 game.ReplicatedStorage.Remotes.PerfectBlockLanded:FireClient(tarPlayer) -- fires a remote to the client to stop the block anim
  140.                             end
  141.                             character:SetAttribute("Stun",true) -- stun the attacker
  142.                             character:SetAttribute("StunTimer",tick()) -- add a timer used for checks
  143.                             task.wait(blockStunTime)
  144.                             if tick() - character:GetAttribute("StunTimer") >= blockStunTime then -- if they weren't stunned again unstun them
  145.                                 character:SetAttribute("Stun", false)
  146.                                 character:SetAttribute("StunTimer",0)
  147.                             end
  148.                             return
  149.                         end
  150.                         local newDamage = damage * character:GetAttribute("BlockDamage") -- calculate the new damage to be applied
  151.                         table.insert(recentHit, target.Parent) -- add target to the debounce
  152.  
  153.                         if hum.Health - newDamage <=0 and hum.Health > 0 then -- if the new damage would kill the target
  154.                             local gui = game.ReplicatedStorage.BillboardGui:Clone() -- clone damage indicator gui
  155.                             debris:AddItem(gui,1)
  156.                             gui.Parent = target.Parent
  157.                             gui.DamageIndicate.Text = tostring(-newDamage)
  158.                             task.delay(task.wait(), function() -- function slowly makes the text rise and turn invisible
  159.                                 for i = 0, 10 , .01 do
  160.                                     if gui == nil then return end
  161.                                     gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  162.                                     if gui:FindFirstChild("DamageIndicate") then
  163.                                         gui.DamageIndicate.TextTransparency += 0.05
  164.                                     end
  165.  
  166.                                     task.wait(0.01)
  167.                                 end
  168.                             end)
  169.                             player.leaderstats.kills.Value +=1
  170.                             AttackPhysics.RagdollCharacter(target.Parent)
  171.                             target.Parent:SetAttribute("RagTimer", tick())
  172.                             AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  173.                             hum:TakeDamage(newDamage)
  174.                             task.wait(reTime)
  175.                             table.remove(recentHit, table.find(recentHit, target.Parent))
  176.                             if target.Parent == nil then return end
  177.                             if tick() - target.Parent:GetAttribute("RagTimer") >= reTime then
  178.                                 AttackPhysics.Unragdoll(target.Parent)
  179.                             end
  180.                             return  -- returning so that the rest of the code wont run
  181.                         end
  182.                         hum:TakeDamage(newDamage) -- take new damage
  183.                         local gui = game.ReplicatedStorage.BillboardGui:Clone() -- clone damage indication gui
  184.                         debris:AddItem(gui,1)
  185.                         gui.Parent = target.Parent
  186.                         gui.DamageIndicate.Text = tostring(-newDamage)
  187.                         task.delay(task.wait(), function()
  188.                             for i = 0, 10 , .01 do
  189.                                 if gui == nil then return end
  190.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  191.                                 if gui:FindFirstChild("DamageIndicate") then
  192.                                     gui.DamageIndicate.TextTransparency += 0.05
  193.                                 end
  194.  
  195.                                 task.wait(0.01)
  196.                             end
  197.                         end)
  198.                         character.Humanoid.Died:Connect(function() -- if the character dies find the target and unstun them
  199.                             if  target.Parent then
  200.                                 target.Parent:SetAttribute("Stun", false)
  201.                                 target.Parent:SetAttribute("StunTimer",0)
  202.                                 target.Parent.Humanoid.AutoRotate = true
  203.                             end
  204.                         end)
  205.  
  206.                         target.Parent:SetAttribute("Stun", true)
  207.                         target.Parent:SetAttribute("StunTimer", tick())
  208.                         target.Parent.Humanoid.AutoRotate = false
  209.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  210.                         task.wait(stunTime)
  211.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  212.                         if target.Parent == nil then return end
  213.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  214.                             target.Parent:SetAttribute("Stun", false)
  215.                             target.Parent:SetAttribute("StunTimer",0)
  216.                             target.Parent.Humanoid.AutoRotate = true
  217.  
  218.  
  219.                         end
  220.                         return
  221.                     end
  222.                     if target.Parent:GetAttribute("Blocking") == false then -- now for the checks that run if they don't die from the damage
  223.                         table.insert(recentHit, target.Parent)
  224.                         hum:TakeDamage(damage)
  225.                         local gui = game.ReplicatedStorage.BillboardGui:Clone() -- clone damage indication gui
  226.                         debris:AddItem(gui,1)
  227.                         gui.Parent = target.Parent
  228.                         gui.DamageIndicate.Text = tostring(-damage)
  229.                         task.delay(task.wait(), function()
  230.                             for i = 0, 10 , .01 do
  231.                                 if gui == nil then return end
  232.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  233.                                 if gui:FindFirstChild("DamageIndicate") then
  234.                                     gui.DamageIndicate.TextTransparency += 0.05
  235.                                 end
  236.  
  237.                                 task.wait(0.01)
  238.                             end
  239.                         end)
  240.                         character.Humanoid.Died:Connect(function() -- previously explained
  241.                             if  target.Parent then
  242.                                 target.Parent:SetAttribute("Stun", false)
  243.                                 target.Parent:SetAttribute("StunTimer",0)
  244.                                 target.Parent.Humanoid.AutoRotate = true
  245.                             end
  246.                         end)
  247.  
  248.                         target.Parent:SetAttribute("Stun", true)
  249.                         target.Parent:SetAttribute("StunTimer", tick())
  250.                         target.Parent.Humanoid.AutoRotate = false
  251.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  252.                         task.wait(stunTime)
  253.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  254.                         if target.Parent == nil then return end
  255.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  256.                             target.Parent:SetAttribute("Stun", false)
  257.                             target.Parent:SetAttribute("StunTimer",0)
  258.                             target.Parent.Humanoid.AutoRotate = true
  259.  
  260.  
  261.                         end
  262.                         task.wait(combatDuration)
  263.  
  264.                         if character == nil then return end
  265.                         if tick() - character:GetAttribute("CombatTimer") >= combatDuration then
  266.                             character:SetAttribute("CombatTimer", 0)
  267.                             character:SetAttribute("Combat", false)
  268.                         end
  269.                         if target.Parent == nil then return end
  270.                         if tick() - target.Parent:GetAttribute("CombatTimer") >= combatDuration then
  271.                             target.Parent:SetAttribute("CombatTimer", 0)
  272.                             target.Parent:SetAttribute("Combat", false)
  273.  
  274.  
  275.                         end
  276.                     elseif target.Parent:GetAttribute("Blocking") == true then -- if they were blocking
  277.                         if target.Parent:GetAttribute("PerfectBlock") == true then -- check if perfect block was true
  278.                             local tarPlayer = game.Players:GetPlayerFromCharacter(target.Parent)
  279.                             if tarPlayer then
  280.                                 game.ReplicatedStorage.Remotes.PerfectBlockLanded:FireClient(tarPlayer)
  281.                             end
  282.                             character:SetAttribute("Stun",true)
  283.                             character:SetAttribute("StunTimer",tick())
  284.                             task.wait(blockStunTime)
  285.                             if tick() - character:GetAttribute("StunTimer") >= blockStunTime then
  286.                                 character:SetAttribute("Stun", false)
  287.                                 character:SetAttribute("StunTimer",0)
  288.                             end
  289.                             return
  290.                         end
  291.                         local newDamage = damage * target.Parent:GetAttribute("BlockDamage") -- create new damage
  292.                         table.insert(recentHit, target.Parent)
  293.                         hum:TakeDamage(newDamage)
  294.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  295.                         debris:AddItem(gui,1)
  296.                         gui.Parent = target.Parent
  297.                         gui.DamageIndicate.Text = tostring(-newDamage)
  298.                         task.delay(task.wait(), function()
  299.                             for i = 0, 10 , .01 do
  300.                                 if gui == nil then return end
  301.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  302.                                 if gui:FindFirstChild("DamageIndicate") then
  303.                                     gui.DamageIndicate.TextTransparency += 0.05
  304.                                 end
  305.  
  306.                                 task.wait(0.01)
  307.                             end
  308.                         end)
  309.                         character.Humanoid.Died:Connect(function()
  310.                             if  target.Parent then
  311.                                 target.Parent:SetAttribute("Stun", false)
  312.                                 target.Parent:SetAttribute("StunTimer",0)
  313.                                 target.Parent.Humanoid.AutoRotate = true
  314.                             end
  315.                         end)
  316.  
  317.                         target.Parent:SetAttribute("Stun", true)
  318.                         target.Parent:SetAttribute("StunTimer", tick())
  319.                         target.Parent.Humanoid.AutoRotate = false
  320.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  321.                         task.wait(stunTime)
  322.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  323.                         if target.Parent == nil then return end
  324.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  325.                             target.Parent:SetAttribute("Stun", false)
  326.                             target.Parent:SetAttribute("StunTimer",0)
  327.                             target.Parent.Humanoid.AutoRotate = true
  328.  
  329.  
  330.                         end
  331.                         task.wait(combatDuration)
  332.  
  333.                         if character == nil then return end
  334.                         if tick() - character:GetAttribute("CombatTimer") >= combatDuration then
  335.                             character:SetAttribute("CombatTimer", 0)
  336.                             character:SetAttribute("Combat", false)
  337.                         end
  338.                         if target.Parent == nil then return end
  339.                         if tick() - target.Parent:GetAttribute("CombatTimer") >= combatDuration then
  340.                             target.Parent:SetAttribute("CombatTimer", 0)
  341.                             target.Parent:SetAttribute("Combat", false)
  342.  
  343.  
  344.                         end
  345.                     end
  346.  
  347.                 end
  348.             elseif hum and count >= maxCombo and FalseConditions(falseConditionsTable,target) == false and TrueConditions(trueConditionsTable,target) == true then -- same as before but only if the combo count is the max combo
  349.  
  350.  
  351.                 if target.Parent ~= player.Character and not table.find(recentHit, target.Parent) then
  352.                     local clone = bloodVFX.BloodVFX:Clone()
  353.                     clone.Parent = target.Parent:FindFirstChild("HumanoidRootPart")
  354.                     task.delay(2,function()
  355.                         for i, emitter in pairs(clone:GetDescendants()) do
  356.                             if emitter:IsA("ParticleEmitter") then
  357.                                 emitter.Enabled = false
  358.                             end
  359.                         end
  360.                         task.wait(0.5)
  361.                         clone:Destroy()
  362.  
  363.                     end)
  364.                     game.Debris:AddItem(clone,2)
  365.                     character:SetAttribute("Combat", true)
  366.                     character:SetAttribute("CombatTimer", tick())
  367.                     target.Parent:SetAttribute("Combat", true)
  368.                     target.Parent:SetAttribute("CombatTimer", tick())
  369.  
  370.                     if hum.Health - damage <= 0  and hum.Health > 0 and not table.find(recentHit, target.Parent) and target.Parent:GetAttribute("Blocking") == false then -- explained previously, all code after this is practically the same, but done this way incase any special thing happens when the combo's last hit is used.
  371.  
  372.                         table.insert(recentHit, target.Parent)
  373.  
  374.  
  375.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  376.                         debris:AddItem(gui,1)
  377.                         gui.Parent = target.Parent
  378.                         gui.DamageIndicate.Text = tostring(-damage)
  379.                         task.delay(task.wait(), function()
  380.                             for i = 0, 10 , .01 do
  381.                                 if gui == nil then return end
  382.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  383.                                 if gui:FindFirstChild("DamageIndicate") then
  384.                                     gui.DamageIndicate.TextTransparency += 0.05
  385.                                 end
  386.  
  387.                                 task.wait(0.01)
  388.                             end
  389.                         end)
  390.                         player.leaderstats.kills.Value +=1
  391.                         AttackPhysics.RagdollCharacter(target.Parent)
  392.                         target.Parent:SetAttribute("RagTimer", tick())
  393.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  394.                         hum:TakeDamage(damage)
  395.                         task.wait(reTime)
  396.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  397.                         if target.Parent == nil then return end
  398.                         if tick() - target.Parent:GetAttribute("RagTimer") >= reTime then
  399.                             AttackPhysics.Unragdoll(target.Parent)
  400.                         end
  401.                         return
  402.                     elseif hum.Health - damage <= 0  and hum.Health > 0 and not table.find(recentHit, target.Parent) and target.Parent:GetAttribute("Blocking") == true then
  403.                         if target.Parent:GetAttribute("PerfectBlock") == true then
  404.                             local tarPlayer = game.Players:GetPlayerFromCharacter(target.Parent)
  405.                             if tarPlayer then
  406.                                 game.ReplicatedStorage.Remotes.PerfectBlockLanded:FireClient(tarPlayer)
  407.                             end
  408.                             character:SetAttribute("Stun",true)
  409.                             character:SetAttribute("StunTimer",tick())
  410.                             task.wait(blockStunTime)
  411.                             if tick() - character:GetAttribute("StunTimer") >= blockStunTime then
  412.                                 character:SetAttribute("Stun", false)
  413.                                 character:SetAttribute("StunTimer",0)
  414.                             end
  415.                             return
  416.                         end
  417.                         local newDamage = damage * character:GetAttribute("BlockDamage")
  418.                         table.insert(recentHit, target.Parent)
  419.  
  420.                         if hum.Health - newDamage <=0 and hum.Health > 0 then
  421.                             local gui = game.ReplicatedStorage.BillboardGui:Clone()
  422.                             debris:AddItem(gui,1)
  423.                             gui.Parent = target.Parent
  424.                             gui.DamageIndicate.Text = tostring(-newDamage)
  425.                             task.delay(task.wait(), function()
  426.                                 for i = 0, 10 , .01 do
  427.                                     if gui == nil then return end
  428.                                     gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  429.                                     if gui:FindFirstChild("DamageIndicate") then
  430.                                         gui.DamageIndicate.TextTransparency += 0.05
  431.                                     end
  432.  
  433.                                     task.wait(0.01)
  434.                                 end
  435.                             end)
  436.                             player.leaderstats.kills.Value +=1
  437.                             AttackPhysics.RagdollCharacter(target.Parent)
  438.                             target.Parent:SetAttribute("RagTimer", tick())
  439.                             AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  440.                             hum:TakeDamage(newDamage)
  441.                             task.wait(reTime)
  442.                             table.remove(recentHit, table.find(recentHit, target.Parent))
  443.                             if target.Parent == nil then return end
  444.                             if tick() - target.Parent:GetAttribute("RagTimer") >= reTime then
  445.                                 AttackPhysics.Unragdoll(target.Parent)
  446.                             end
  447.                             return 
  448.                         end
  449.                         hum:TakeDamage(newDamage)
  450.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  451.                         debris:AddItem(gui,1)
  452.                         gui.Parent = target.Parent
  453.                         gui.DamageIndicate.Text = tostring(-newDamage)
  454.                         task.delay(task.wait(), function()
  455.                             for i = 0, 10 , .01 do
  456.                                 if gui == nil then return end
  457.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  458.                                 if gui:FindFirstChild("DamageIndicate") then
  459.                                     gui.DamageIndicate.TextTransparency += 0.05
  460.                                 end
  461.  
  462.                                 task.wait(0.01)
  463.                             end
  464.                         end)
  465.                         character.Humanoid.Died:Connect(function()
  466.                             if  target.Parent then
  467.                                 target.Parent:SetAttribute("Stun", false)
  468.                                 target.Parent:SetAttribute("StunTimer",0)
  469.                                 target.Parent.Humanoid.AutoRotate = true
  470.                             end
  471.                         end)
  472.  
  473.                         target.Parent:SetAttribute("Stun", true)
  474.                         target.Parent:SetAttribute("StunTimer", tick())
  475.                         target.Parent.Humanoid.AutoRotate = false
  476.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  477.                         task.wait(stunTime)
  478.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  479.                         if target.Parent == nil then return end
  480.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  481.                             target.Parent:SetAttribute("Stun", false)
  482.                             target.Parent:SetAttribute("StunTimer",0)
  483.                             target.Parent.Humanoid.AutoRotate = true
  484.  
  485.  
  486.                         end
  487.                         return
  488.                     end
  489.                     if target.Parent:GetAttribute("Blocking") == false then
  490.                         table.insert(recentHit, target.Parent)
  491.                         hum:TakeDamage(damage)
  492.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  493.                         debris:AddItem(gui,1)
  494.                         gui.Parent = target.Parent
  495.                         gui.DamageIndicate.Text = tostring(-damage)
  496.                         task.delay(task.wait(), function()
  497.                             for i = 0, 10 , .01 do
  498.                                 if gui == nil then return end
  499.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  500.                                 if gui:FindFirstChild("DamageIndicate") then
  501.                                     gui.DamageIndicate.TextTransparency += 0.05
  502.                                 end
  503.  
  504.                                 task.wait(0.01)
  505.                             end
  506.                         end)
  507.                         character.Humanoid.Died:Connect(function()
  508.                             if  target.Parent then
  509.                                 target.Parent:SetAttribute("Stun", false)
  510.                                 target.Parent:SetAttribute("StunTimer",0)
  511.                                 target.Parent.Humanoid.AutoRotate = true
  512.                             end
  513.                         end)
  514.  
  515.  
  516.                         target.Parent:SetAttribute("Stun", true)
  517.                         target.Parent:SetAttribute("StunTimer", tick())
  518.                         target.Parent.Humanoid.AutoRotate = false
  519.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  520.                         task.wait(stunTime)
  521.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  522.                         if target.Parent == nil then return end
  523.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  524.                             target.Parent:SetAttribute("Stun", false)
  525.                             target.Parent:SetAttribute("StunTimer",0)
  526.                             target.Parent.Humanoid.AutoRotate = true
  527.  
  528.  
  529.                         end
  530.                         task.wait(combatDuration)
  531.  
  532.                         if character == nil then return end
  533.                         if tick() - character:GetAttribute("CombatTimer") >= combatDuration then
  534.                             character:SetAttribute("CombatTimer", 0)
  535.                             character:SetAttribute("Combat", false)
  536.                         end
  537.                         if target.Parent == nil then return end
  538.                         if tick() - target.Parent:GetAttribute("CombatTimer") >= combatDuration then
  539.                             target.Parent:SetAttribute("CombatTimer", 0)
  540.                             target.Parent:SetAttribute("Combat", false)
  541.  
  542.  
  543.                         end
  544.                     elseif target.Parent:GetAttribute("Blocking") == true then
  545.                         if target.Parent:GetAttribute("PerfectBlock") == true then
  546.                             local tarPlayer = game.Players:GetPlayerFromCharacter(target.Parent)
  547.                             if tarPlayer then
  548.                                 game.ReplicatedStorage.Remotes.PerfectBlockLanded:FireClient(tarPlayer)
  549.                             end
  550.                             character:SetAttribute("Stun",true)
  551.                             character:SetAttribute("StunTimer",tick())
  552.                             task.wait(blockStunTime)
  553.                             if tick() - character:GetAttribute("StunTimer") >= blockStunTime then
  554.                                 character:SetAttribute("Stun", false)
  555.                                 character:SetAttribute("StunTimer",0)
  556.                             end
  557.                             return
  558.                         end
  559.                         local newDamage = damage * target.Parent:GetAttribute("BlockDamage")
  560.                         table.insert(recentHit, target.Parent)
  561.                         hum:TakeDamage(newDamage)
  562.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  563.                         debris:AddItem(gui,1)
  564.                         gui.Parent = target.Parent
  565.                         gui.DamageIndicate.Text = tostring(-newDamage)
  566.                         task.delay(task.wait(), function()
  567.                             for i = 0, 10 , .01 do
  568.                                 if gui == nil then return end
  569.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  570.                                 if gui:FindFirstChild("DamageIndicate") then
  571.                                     gui.DamageIndicate.TextTransparency += 0.05
  572.                                 end
  573.  
  574.                                 task.wait(0.01)
  575.                             end
  576.                         end)
  577.                         character.Humanoid.Died:Connect(function()
  578.                             if  target.Parent then
  579.                                 target.Parent:SetAttribute("Stun", false)
  580.                                 target.Parent:SetAttribute("StunTimer",0)
  581.                                 target.Parent.Humanoid.AutoRotate = true
  582.                             end
  583.                         end)
  584.  
  585.  
  586.                         target.Parent:SetAttribute("Stun", true)
  587.                         target.Parent:SetAttribute("StunTimer", tick())
  588.                         target.Parent.Humanoid.AutoRotate = false
  589.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),20,10)
  590.                         task.wait(stunTime)
  591.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  592.                         if target.Parent == nil then return end
  593.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  594.                             target.Parent:SetAttribute("Stun", false)
  595.                             target.Parent:SetAttribute("StunTimer",0)
  596.                             target.Parent.Humanoid.AutoRotate = true
  597.  
  598.  
  599.                         end
  600.                         task.wait(combatDuration)
  601.  
  602.                         if character == nil then return end
  603.                         if tick() - character:GetAttribute("CombatTimer") >= combatDuration then
  604.                             character:SetAttribute("CombatTimer", 0)
  605.                             character:SetAttribute("Combat", false)
  606.                         end
  607.                         if target.Parent == nil then return end
  608.                         if tick() - target.Parent:GetAttribute("CombatTimer") >= combatDuration then
  609.                             target.Parent:SetAttribute("CombatTimer", 0)
  610.                             target.Parent:SetAttribute("Combat", false)
  611.  
  612.  
  613.                         end
  614.                     end
  615.  
  616.                 end
  617.             else
  618.                 return
  619.  
  620.             end
  621.  
  622.  
  623.  
  624.         end)
  625.         debris:AddItem(damageBox,0.1)
  626.  
  627.     else
  628.         return
  629.     end
  630.     task.wait(0.5)
  631.     character:SetAttribute("Attacking", false)
  632.  
  633.  
  634. end)
  635.  
  636. remotes.ClientSpecialRemote.OnServerEvent:Connect(function(player) -- fires when a player uses a special move of the sword. Same logic as the client click remote only this has a few slight differences, such as damage box shape and knock back and checks.
  637.     local character = player.Character
  638.  
  639.     if character then
  640.         character:SetAttribute("Attacking", true)
  641.         local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  642.  
  643.         -- Create the damage box
  644.         local damageBox = Instance.new("Part")
  645.  
  646.         damageBox.CanTouch = true
  647.         damageBox.Size = Vector3.new(6, 15, 15) -- Adjust the size as needed
  648.         damageBox.Shape = Enum.PartType.Cylinder
  649.         damageBox.Anchored = false
  650.         damageBox.CanCollide = false
  651.         damageBox.Transparency = 0.5
  652.         damageBox.BrickColor = BrickColor.new("Bright red")
  653.         damageBox.Name = "DamageBox"
  654.         damageBox.Parent = game.Workspace
  655.         local rotation = CFrame.fromEulerAnglesXYZ(0, 0, math.rad(-90))
  656.         damageBox.CFrame = humanoidRootPart.CFrame   * rotation -- Adjust the distance in front of the player      
  657.         damageBox.Touched:Connect(function(target)
  658.             if target.Parent == nil then return end
  659.             if target == nil then return end
  660.  
  661.             local hum = target.Parent:FindFirstChildOfClass("Humanoid")
  662.  
  663.             if hum  and  TrueConditions(trueConditionsTable,target) == true then
  664.  
  665.                 if target.Parent ~= player.Character and not table.find(recentHit, target.Parent) then
  666.                     local clone = bloodVFX.BloodVFX:Clone()
  667.                     clone.Parent = target.Parent:FindFirstChild("HumanoidRootPart")
  668.                     task.delay(2,function()
  669.                         for i, emitter in pairs(clone:GetDescendants()) do
  670.                             if emitter:IsA("ParticleEmitter") then
  671.                                 emitter.Enabled = false
  672.                             end
  673.                         end
  674.                         task.wait(0.5)
  675.                         clone:Destroy()
  676.  
  677.                     end)
  678.                     character:SetAttribute("Combat", true)
  679.                     character:SetAttribute("CombatTimer", tick())
  680.                     target.Parent:SetAttribute("Combat", true)
  681.                     target.Parent:SetAttribute("CombatTimer", tick())
  682.  
  683.                     if hum.Health - specialDamage <= 0  and hum.Health > 0 and not table.find(recentHit, target.Parent) and target.Parent:GetAttribute("Blocking") == false then
  684.  
  685.                         table.insert(recentHit, target.Parent)
  686.  
  687.  
  688.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  689.                         debris:AddItem(gui,1)
  690.                         gui.Parent = target.Parent
  691.                         gui.DamageIndicate.Text = tostring(-specialDamage)
  692.                         task.delay(task.wait(), function()
  693.                             for i = 0, 10 , .01 do
  694.                                 if gui == nil then return end
  695.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  696.                                 if gui:FindFirstChild("DamageIndicate") then
  697.                                     gui.DamageIndicate.TextTransparency += 0.05
  698.                                 end
  699.  
  700.                                 task.wait(0.01)
  701.                             end
  702.                         end)
  703.                         player.leaderstats.kills.Value +=1
  704.                         AttackPhysics.RagdollCharacter(target.Parent)
  705.                         target.Parent:SetAttribute("RagTimer", tick())
  706.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),50,30)
  707.                         hum:TakeDamage(specialDamage)
  708.                         task.wait(reTime)
  709.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  710.                         if target.Parent == nil then return end
  711.                         if tick() - target.Parent:GetAttribute("RagTimer") >= reTime then
  712.                             AttackPhysics.Unragdoll(target.Parent)
  713.                         end
  714.                         return
  715.                     elseif hum.Health - specialDamage <= 0  and hum.Health > 0 and not table.find(recentHit, target.Parent) and target.Parent:GetAttribute("Blocking") == true then
  716.                         if target.Parent:GetAttribute("PerfectBlock") == true then
  717.                             local tarPlayer = game.Players:GetPlayerFromCharacter(target.Parent)
  718.                             if tarPlayer then
  719.                                 game.ReplicatedStorage.Remotes.PerfectBlockLanded:FireClient(tarPlayer)
  720.                             end
  721.  
  722.                             character:SetAttribute("Stun",true)
  723.                             character:SetAttribute("StunTimer",tick())
  724.                             task.wait(blockStunTime)
  725.                             if tick() - character:GetAttribute("StunTimer") >= blockStunTime then
  726.                                 character:SetAttribute("Stun", false)
  727.                                 character:SetAttribute("StunTimer",0)
  728.                             end
  729.                             return
  730.                         end
  731.                         local newDamage = specialDamage * character:GetAttribute("BlockDamage")
  732.                         table.insert(recentHit, target.Parent)
  733.  
  734.                         if hum.Health - newDamage <=0 and hum.Health > 0 then
  735.                             local gui = game.ReplicatedStorage.BillboardGui:Clone()
  736.                             debris:AddItem(gui,1)
  737.                             gui.Parent = target.Parent
  738.                             gui.DamageIndicate.Text = tostring(-newDamage)
  739.                             task.delay(task.wait(), function()
  740.                                 for i = 0, 10 , .01 do
  741.                                     if gui == nil then return end
  742.                                     gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  743.                                     if gui:FindFirstChild("DamageIndicate") then
  744.                                         gui.DamageIndicate.TextTransparency += 0.05
  745.                                     end
  746.  
  747.                                     task.wait(0.01)
  748.                                 end
  749.                             end)
  750.                             player.leaderstats.kills.Value +=1
  751.                             AttackPhysics.RagdollCharacter(target.Parent)
  752.                             target.Parent:SetAttribute("RagTimer", tick())
  753.                             AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),50,30)
  754.                             hum:TakeDamage(newDamage)
  755.                             task.wait(reTime)
  756.                             table.remove(recentHit, table.find(recentHit, target.Parent))
  757.                             if target.Parent == nil then return end
  758.                             if tick() - target.Parent:GetAttribute("RagTimer") >= reTime then
  759.                                 AttackPhysics.Unragdoll(target.Parent)
  760.                             end
  761.                             return 
  762.                         end
  763.                         hum:TakeDamage(newDamage)
  764.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  765.                         debris:AddItem(gui,1)
  766.                         gui.Parent = target.Parent
  767.                         gui.DamageIndicate.Text = tostring(-newDamage)
  768.                         task.delay(task.wait(), function()
  769.                             for i = 0, 10 , .01 do
  770.                                 if gui == nil then return end
  771.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  772.                                 if gui:FindFirstChild("DamageIndicate") then
  773.                                     gui.DamageIndicate.TextTransparency += 0.05
  774.                                 end
  775.  
  776.                                 task.wait(0.01)
  777.                             end
  778.                         end)
  779.                         character.Humanoid.Died:Connect(function()
  780.                             if  target.Parent then
  781.                                 target.Parent:SetAttribute("Stun", false)
  782.                                 target.Parent:SetAttribute("StunTimer",0)
  783.                                 target.Parent.Humanoid.AutoRotate = true
  784.                             end
  785.                         end)
  786.  
  787.                         target.Parent:SetAttribute("Stun", true)
  788.                         target.Parent:SetAttribute("StunTimer", tick())
  789.                         target.Parent.Humanoid.AutoRotate = false
  790.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),50,30)
  791.                         task.wait(stunTime)
  792.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  793.                         if target.Parent == nil then return end
  794.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  795.                             target.Parent:SetAttribute("Stun", false)
  796.                             target.Parent:SetAttribute("StunTimer",0)
  797.                             target.Parent.Humanoid.AutoRotate = true
  798.  
  799.  
  800.                         end
  801.                         return
  802.                     end
  803.                     if target.Parent:GetAttribute("Blocking") == false then
  804.                         table.insert(recentHit, target.Parent)
  805.                         hum:TakeDamage(specialDamage)
  806.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  807.                         debris:AddItem(gui,1)
  808.                         gui.Parent = target.Parent
  809.                         gui.DamageIndicate.Text = tostring(-specialDamage)
  810.                         task.delay(task.wait(), function()
  811.                             for i = 0, 10 , .01 do
  812.                                 if gui == nil then return end
  813.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  814.                                 if gui:FindFirstChild("DamageIndicate") then
  815.                                     gui.DamageIndicate.TextTransparency += 0.05
  816.                                 end
  817.  
  818.                                 task.wait(0.01)
  819.                             end
  820.                         end)
  821.                         character.Humanoid.Died:Connect(function()
  822.                             if  target.Parent then
  823.                                 target.Parent:SetAttribute("Stun", false)
  824.                                 target.Parent:SetAttribute("StunTimer",0)
  825.                                 target.Parent.Humanoid.AutoRotate = true
  826.                             end
  827.                         end)
  828.  
  829.  
  830.                         target.Parent:SetAttribute("Stun", true)
  831.                         target.Parent:SetAttribute("StunTimer", tick())
  832.                         target.Parent.Humanoid.AutoRotate = false
  833.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),50,30)
  834.                         task.wait(stunTime)
  835.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  836.                         if target.Parent == nil then return end
  837.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  838.                             target.Parent:SetAttribute("Stun", false)
  839.                             target.Parent:SetAttribute("StunTimer",0)
  840.                             target.Parent.Humanoid.AutoRotate = true
  841.  
  842.  
  843.                         end
  844.                         task.wait(combatDuration)
  845.  
  846.                         if character == nil then return end
  847.                         if tick() - character:GetAttribute("CombatTimer") >= combatDuration then
  848.                             character:SetAttribute("CombatTimer", 0)
  849.                             character:SetAttribute("Combat", false)
  850.                         end
  851.                         if target.Parent == nil then return end
  852.                         if tick() - target.Parent:GetAttribute("CombatTimer") >= combatDuration then
  853.                             target.Parent:SetAttribute("CombatTimer", 0)
  854.                             target.Parent:SetAttribute("Combat", false)
  855.  
  856.  
  857.                         end
  858.                     elseif target.Parent:GetAttribute("Blocking") == true then
  859.                         if target.Parent:GetAttribute("PerfectBlock") == true then
  860.                             local tarPlayer = game.Players:GetPlayerFromCharacter(target.Parent)
  861.                             if tarPlayer then
  862.                                 game.ReplicatedStorage.Remotes.PerfectBlockLanded:FireClient(tarPlayer)
  863.                             end
  864.                             character:SetAttribute("Stun",true)
  865.                             character:SetAttribute("StunTimer",tick())
  866.                             task.wait(blockStunTime)
  867.                             if tick() - character:GetAttribute("StunTimer") >= blockStunTime then
  868.                                 character:SetAttribute("Stun", false)
  869.                                 character:SetAttribute("StunTimer",0)
  870.                             end
  871.                             return
  872.                         end
  873.                         local newDamage = specialDamage * target.Parent:GetAttribute("BlockDamage")
  874.                         table.insert(recentHit, target.Parent)
  875.                         hum:TakeDamage(newDamage)
  876.                         local gui = game.ReplicatedStorage.BillboardGui:Clone()
  877.                         debris:AddItem(gui,1)
  878.                         gui.Parent = target.Parent
  879.                         gui.DamageIndicate.Text = tostring(-newDamage)
  880.                         task.delay(task.wait(), function()
  881.                             for i = 0, 10 , .01 do
  882.                                 if gui == nil then return end
  883.                                 gui.ExtentsOffset = gui.ExtentsOffset + Vector3.new(0,0.01,0)
  884.                                 if gui:FindFirstChild("DamageIndicate") then
  885.                                     gui.DamageIndicate.TextTransparency += 0.05
  886.                                 end
  887.  
  888.                                 task.wait(0.01)
  889.                             end
  890.                         end)
  891.                         character.Humanoid.Died:Connect(function()
  892.                             if  target.Parent then
  893.                                 target.Parent:SetAttribute("Stun", false)
  894.                                 target.Parent:SetAttribute("StunTimer",0)
  895.                                 target.Parent.Humanoid.AutoRotate = true
  896.                             end
  897.                         end)
  898.  
  899.                         target.Parent:SetAttribute("Stun", true)
  900.                         target.Parent:SetAttribute("StunTimer", tick())
  901.                         target.Parent.Humanoid.AutoRotate = false
  902.                         AttackPhysics.SpecificKB(target.Parent, character:WaitForChild("HumanoidRootPart"),50,30)
  903.                         task.wait(stunTime)
  904.                         table.remove(recentHit, table.find(recentHit, target.Parent))
  905.                         if target.Parent == nil then return end
  906.                         if tick() - target.Parent:GetAttribute("StunTimer") >= stunTime then
  907.                             target.Parent:SetAttribute("Stun", false)
  908.                             target.Parent:SetAttribute("StunTimer",0)
  909.                             target.Parent.Humanoid.AutoRotate = true
  910.  
  911.  
  912.                         end
  913.                         task.wait(combatDuration)
  914.  
  915.                         if character == nil then return end
  916.                         if tick() - character:GetAttribute("CombatTimer") >= combatDuration then
  917.                             character:SetAttribute("CombatTimer", 0)
  918.                             character:SetAttribute("Combat", false)
  919.                         end
  920.                         if target.Parent == nil then return end
  921.                         if tick() - target.Parent:GetAttribute("CombatTimer") >= combatDuration then
  922.                             target.Parent:SetAttribute("CombatTimer", 0)
  923.                             target.Parent:SetAttribute("Combat", false)
  924.  
  925.  
  926.                         end
  927.                     end
  928.                 else
  929.                     return
  930.                 end
  931.             else
  932.                 return
  933.             end
  934.         end)
  935.     else
  936.         return
  937.     end
  938.  
  939. end)
  940.  
  941. remotes.ClientBlockRemote.OnServerEvent:Connect(function(player, blockCd) -- fires when the player presses the block button
  942.     local character = player.Character
  943.  
  944.     if character then
  945.         character:SetAttribute("Blocking",true) -- set blocking to true
  946.         task.spawn(function() -- sets perfect block to true temporarily
  947.             character:SetAttribute("PerfectBlock", true)
  948.             task.wait(perfectBlockTime)
  949.             character:SetAttribute("PerfectBlock", false)
  950.         end)
  951.         task.wait(blockCd) -- set blocking back to false after a cool down
  952.         if character:GetAttribute("Blocking") == true then
  953.             character:SetAttribute("Blocking",false)
  954.             remotes.ClientBlockRemote:FireClient(player)
  955.         end
  956.     else
  957.         return
  958.     end
  959.  
  960.  
  961.  
  962. end)
  963.  
  964. remotes.AdjustSpeedRemote.OnServerEvent:Connect(function(player, slowWholeNumber, waitTime) -- slows speed when the player uses a move
  965.     local character = player.Character
  966.  
  967.     if character then
  968.         local currentSpeed = character:GetAttribute("Speed")
  969.  
  970.         if slowWholeNumber > 0 then
  971.             local adjustment = currentSpeed - (currentSpeed / slowWholeNumber)
  972.             remotes.SpeedReduced:FireClient(player,currentSpeed) -- fires client to let them know of the speed decrease, used to re add speed if a perfect block is performed
  973.             if character:GetAttribute("Speed") + adjustment > 0 then -- if we don't slow them too much
  974.                 character:SetAttribute("Speed", character:GetAttribute("Speed") - adjustment)
  975.                 task.wait(waitTime) -- cool down
  976.                 if character:GetAttribute("Speed") < currentSpeed then -- if the speed is still reduced (if a perfect block wasn't landed)
  977.                     character:SetAttribute("Speed", character:GetAttribute("Speed") + adjustment)
  978.                 end
  979.  
  980.             else
  981.                 return
  982.             end
  983.  
  984.         else
  985.             return
  986.         end
  987.     else
  988.         return
  989.     end
  990. end)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement