Hello!
Whenever a player punches someone who is punching them, a certain remote will be spammed and cause a lot of issues for various scripts. I have wrapped all my remote fires in debounces but still don’t know why this issue persists, if anyone can help, it would be appreciated!
-- // Services // --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
-- // Variables // --
local CombatEvent = ReplicatedStorage:WaitForChild("Combat").Combat
local ShakeEvent = ReplicatedStorage:WaitForChild("Combat").Shake
local StunHandlerV2 = require(game:GetService("ServerScriptService"):WaitForChild("Modules").StunHandlerV2)
local SpeedHandler = require(game:GetService("ServerScriptService"):WaitForChild("Modules").SpeedHandler)
local cooldown = .3
local damage = 4
-- // Folders // --
local Animations = script:WaitForChild("Animations")
local enemyAnimations = script:WaitForChild("EnemyAnims")
-- // Tables // --
local anims = {
Animations:WaitForChild("LeftPunch1"),
Animations:WaitForChild("RightPunch2"),
Animations:WaitForChild("LeftKick3"),
Animations:WaitForChild("RightKick4"),
Animations:WaitForChild("FrontFlipKick5")
}
local eAnims = {
enemyAnimations:WaitForChild("EnemyReaction"),
enemyAnimations:WaitForChild("BlockBreak"),
enemyAnimations:WaitForChild("BlockParry")
}
-- // Events // --
CombatEvent.OnServerEvent:Connect(function(plr, counter)
-- Variables
local Hitbox = ReplicatedStorage:WaitForChild("Combat").Hitboxes.PunchHitbox:Clone()
local Character = plr.Character
local Animator = Character:WaitForChild("Humanoid").Animator
-- Functions
local function CreateBlockBreakEffect(pos, colour)
-- Creates a block break effect at the designated position.
local FX = Instance.new("Part") FX.Parent = workspace:WaitForChild("FX")
FX.Name = "CombatHit"
FX.Shape = "Ball"
FX.CanCollide = false
FX.Anchored = true
FX.Material = "ForceField"
FX.Color = colour
FX.CFrame = pos.CFrame
Debris:AddItem(FX, 1)
end
-- Make a value so we can tell when the player is attacking.
local Attacking = Instance.new("BoolValue") Attacking.Parent = Character.Humanoid
Attacking.Name = "Attacking"
Debris:AddItem(Attacking, .75)
-- Reduce the humanoid's walkspeed to 8 for 0.75 seconds and play the combo animations.
coroutine.wrap(SpeedHandler.ReduceSpeed)(Character.Humanoid, .75, 8, 0)
Animator:LoadAnimation(anims[counter]):Play()
local remoteDebounce = false
coroutine.wrap(function()
if counter <= 4 then
-- Less Cooldown
if not remoteDebounce then
CombatEvent:FireClient(plr, cooldown)
remoteDebounce = true
task.wait(1)
remoteDebounce = false
end
elseif counter == 5 then
if not remoteDebounce then
CombatEvent:FireClient(plr, 2)
remoteDebounce = true
task.wait(1)
remoteDebounce = false
end
-- Higher Cooldown
end
end)()
-- Create a new folder for all the hitboxes to stay in.
local folder = Instance.new("Folder") folder.Parent = Character
folder.Name ="Hitboxes"
Hitbox.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,0, -2)
Hitbox.Parent = folder
Debris:AddItem(Hitbox, .5)
Debris:AddItem(folder, .5)
-- Weld the hitbox onto the player and perform a wait so the hitbox has time to load.
local weld = Instance.new("WeldConstraint")
weld.Part0 = Hitbox
weld.Part1 = Character.HumanoidRootPart
weld.Parent = Character
task.wait(0.07)
local ignoreList = {Character:GetDescendants()}
-- Perform a check to see if anything was hit, if so then check if they have a humanoid
for i = 1,15,1 do
if Character:GetAttribute("Stunned", true) then break end
local overlapParameters = OverlapParams.new()
overlapParameters.FilterDescendantsInstances = ignoreList
overlapParameters.FilterType = Enum.RaycastFilterType.Blacklist
overlapParameters.MaxParts = 100
local results = workspace:GetPartsInPart(Hitbox, overlapParameters)
task.wait()
if results ~= nil then
local enemy = nil -- Enemy Humanoid
local enemyPlayer = nil -- Enemy Player
local enemyChar = nil -- Enemy Character
for _, bodyPart in pairs (results) do
if bodyPart.Parent and bodyPart.Parent:IsA("Accessory") then
print("Found Accesory")
table.insert(ignoreList, bodyPart)
else
enemy = bodyPart.Parent:FindFirstChild("Humanoid") or bodyPart.Parent.Parent:FindFirstChild("Humanoid")
enemyChar = bodyPart.Parent
print(bodyPart.Parent)
end
end
-- If we have found a humanoid and they are not dead, we proceed.
if enemy and enemy:GetState() ~= Enum.HumanoidStateType.Dead then
-- Is the current humanoid blocking? If so, we can play a special hit sound and destroy the hitbox.
local blockAction = enemy:FindFirstChild("blockAction")
if blockAction then
local blockSFX = Instance.new("Sound") blockSFX.Parent = enemyChar.HumanoidRootPart blockSFX.SoundId = "rbxassetid://7058511334" blockSFX.PlaybackSpeed = math.random(80,100)/100 blockSFX:Play()
Debris:AddItem(blockSFX, 1)
Hitbox:Destroy()
-- If the block bar's value is greater than 1, we will decrease it else it will guard break.
if blockAction.Value ~= 0 then
blockAction.Value -= 1
if blockAction.Value ~= 0 then
CreateBlockBreakEffect(enemyChar.HumanoidRootPart, Color3.fromRGB(255, 255, 255))
end
-- Play the block break animation on the enemy and remove their block value.
enemy.Animator:LoadAnimation(eAnims[3]):Play()
if blockAction.Value == 0 then
enemy.Animator:LoadAnimation(eAnims[2]):Play()
blockAction:Destroy()
-- Attempts to stop the blocking animation if guard broken.
coroutine.wrap(function()
for i, anims in pairs(enemy:GetPlayingAnimationTracks()) do
if anims.Name == "Block" then
anims:Stop()
end
end
-- Finds the player from the character and sets the isBroken (guardbreak) value to true.
enemyPlayer = game:GetService("Players"):GetPlayerFromCharacter(enemyChar)
if enemyPlayer then
local backpack = enemy:FindFirstChild("Backpack")
if backpack then
local Combat = backpack:FindFirstChild("Combat")
if Combat then
local CombatSystem = backpack:FindFirstChild("CombatSystem")
if CombatSystem then
local isBroken = Combat:FindFirstChild("isBroken")
if isBroken then
-- Set the block broken value to true and creates a special effect.
isBroken.Value = true
CreateBlockBreakEffect(enemyChar.HumanoidRootPart, Color3.fromRGB(255,0,0))
StunHandlerV2.Stun(enemy, 2)
isBroken.Value = false
end
end
end
end
end
end)
end
end
break
else
-- Spawns 2 particle emitters (Effects)
local HitParticle = ReplicatedStorage:WaitForChild("FX").OrangeSpark:Clone()
local HitParticle2 = ReplicatedStorage:WaitForChild("FX").WhiteSpark:Clone()
local HitParticle3 = ReplicatedStorage:WaitForChild("FX").Wisps:Clone()
local enemyRoot = enemyChar:FindFirstChild("HumanoidRootPart")
if enemyRoot then
local attach = Instance.new("Attachment", enemyChar.HumanoidRootPart)
game.Debris:AddItem(attach,.7)
HitParticle.Parent = attach
HitParticle:Emit(5)
game.Debris:AddItem(HitParticle,.7)
HitParticle2.Parent = attach
HitParticle2:Emit(24)
game.Debris:AddItem(HitParticle2,.7)
HitParticle3.Parent = attach
HitParticle3:Emit(6)
game.Debris:AddItem(HitParticle3,.7)
-- Find the last player who hit them (used for rewarding experience).
local tag = enemy:FindFirstChild("hitTag")
if tag then
tag.Value = plr.Name
end
--[[
if enemyPlayer then
ShakeEvent:FireClient(enemyPlayer)
end
ShakeEvent:FireClient(plr)
--]]
enemy:TakeDamage(damage)
enemy.Animator:LoadAnimation(eAnims[1]):Play()
-- Stun the enemy for .75 seconds.
Hitbox:Destroy()
coroutine.wrap(StunHandlerV2.Stun)(enemy, .75)
if counter < 5 then
-- If the combo counter is less than 5, we will play the punch sound effect.
local LightPunchSFX = Instance.new("Sound") LightPunchSFX.Parent = enemyRoot LightPunchSFX.SoundId = "rbxassetid://2974875851" LightPunchSFX.PlaybackSpeed = math.random(80,120)/100 LightPunchSFX:Play()
Debris:AddItem(LightPunchSFX, 1)
elseif counter == 5 then
-- If the combo counter is equal to 5, we will apply knockback to the enemy's character, play a special sound effect
-- and slow down the player's walkspeed.
local HeavyPunchSFX = Instance.new("Sound") HeavyPunchSFX.Parent = enemyRoot HeavyPunchSFX.SoundId = "rbxassetid://541909913" HeavyPunchSFX.Volume = 1 HeavyPunchSFX.PlaybackSpeed = math.random(80,100)/100 HeavyPunchSFX:Play()
Debris:AddItem(HeavyPunchSFX, 1)
local BodyVelocity = Instance.new("BodyVelocity") BodyVelocity.Parent = enemyRoot BodyVelocity.MaxForce = Vector3.new(25000,25000,25000) BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector*50
Debris:AddItem(BodyVelocity, .3)
end
break
end
end
end
end
end
end)
Actual remote firing event:
local remoteDebounce = false
coroutine.wrap(function()
if counter <= 4 then
-- Less Cooldown
if not remoteDebounce then
CombatEvent:FireClient(plr, cooldown)
remoteDebounce = true
task.wait(1)
remoteDebounce = false
end
elseif counter == 5 then
if not remoteDebounce then
CombatEvent:FireClient(plr, 2)
remoteDebounce = true
task.wait(1)
remoteDebounce = false
end
-- Higher Cooldown
end
end)()