Well thats the code some things are explained in the code and if you still have any questions ask me. Maybe someone knows what I can make better in this scirpt because I feel like it can be improved heavily.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local TS = game:GetService("TweenService")
local PunchRemote = ReplicatedStorage.Events.FistCombat
local Debris = game:GetService("Debris")
----- Modules
local DamageIndicatorModule = require(ReplicatedStorage.Modules.DamageIndicator)
local RockModule = require(ReplicatedStorage.Modules.RocksModule)
local Tween = require(SS.Modules.LocalTween)
----- Folders
local AnimationsFolder = script:WaitForChild("Animations")
local PlayerAnimations = AnimationsFolder:WaitForChild("Player")
local EnemyAnimations = AnimationsFolder:WaitForChild("Enemy")
local SoundFolder =script:WaitForChild("Sounds")
------ Player Animations
local Punch1 = PlayerAnimations:WaitForChild("1")
local Punch2 = PlayerAnimations:WaitForChild("2")
local Punch3 = PlayerAnimations:WaitForChild("3")
local Punch4 = PlayerAnimations:WaitForChild("4")
local Punch5 = PlayerAnimations:WaitForChild("Final")
local DownSlam = PlayerAnimations:WaitForChild("DownSlam")
---- Enemy Animations
local LeftHit = EnemyAnimations:WaitForChild("1")
local RightHit = EnemyAnimations:WaitForChild("2")
local LeftHit2 = EnemyAnimations:WaitForChild("3")
local RightHit2 = EnemyAnimations:WaitForChild("4")
local KnockBack = EnemyAnimations:WaitForChild("KnockBack")
local Blocked = EnemyAnimations:WaitForChild("Blocked")
local Break = EnemyAnimations:WaitForChild("Break")
--- Sounds
local PunchSwing = SoundFolder:WaitForChild("SwingFist")
local HitSound = SoundFolder:WaitForChild("Hit")
local Heavy = SoundFolder:WaitForChild("Heavy")
local BlockSound = SoundFolder:WaitForChild("BlockedSound")
local BlockBreakSound = SoundFolder:WaitForChild("BlockBreak")
--- Booleans
local CanHit = true
---- effects
local Effects = ReplicatedStorage:WaitForChild("CombatEffects")
local Effects2 = ReplicatedStorage:WaitForChild("Effects")
local HitEffect = Effects:WaitForChild("HitEffect")
local AttachmentHit = HitEffect.Attachment
local breakEffect = Effects:WaitForChild("BreakEffect")
local AttachmentBreak = breakEffect.Attachment
local BloodEffect = Effects2:WaitForChild("BloodPart")
local BloodHit = BloodEffect.Attachment
local Shake = script:WaitForChild("ShakeScript")
-- Billboards
local StunnedGui = ReplicatedStorage.Effects:WaitForChild("Stunned")
-- Configurations
local BasicDamage = 3 -- changes the damage of the normal hits
local FinalDamage = 6 -- changes the damage of the finale hit
local BasicStun = 0.55 -- changes the time the enemy is stunned after a normal hit
local FinalStun = 3.5 -- changes the time the enemy is stunned after the final hit
local GuardBroken = 3 -- changes the time the enemy is stunned after they got guard broken
local HitAfter = 0.2 -- changes the time the hitbox gets activated after a punch
local HitboxStayTime = 0.4 -- changes the time the hitbox stays
local ResetPlr = 0.3 -- changes the time the plr walkspeed etc gets reseted
-- Booleans
local CanHit = true
local Comboing = false
-- Hit Tracking
local PlayersHit = {}
------- Functions -------
local function NormalPlayerVelocity(char,hum, hrp)
if hrp.Parent:FindFirstChild("SmallMoveVel") then
hrp.Parent:FindFirstChild("SmallMoveVel"):Destroy()
end
if hum.FloorMaterial ~= Enum.Material.Air then
local vel = Instance.new("BodyVelocity")
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = hrp
vel.Velocity = Vector3.new(1,1,1) * hrp.CFrame.LookVector * 5
vel.Name = "SmallMoveVel"
Debris:AddItem(vel,.3)
else
local vel = Instance.new("BodyVelocity")
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = hrp
vel.Velocity = Vector3.new(1,1,1) * hrp.CFrame.LookVector * 5
vel.Name = "SmallMoveVel"
Debris:AddItem(vel,.5)
end
end
local function NormalEnemyVelocity(char,hum, hrp, enemyHRP)
if enemyHRP.Parent:FindFirstChild("SmallMoveVel") then
enemyHRP.Parent:FindFirstChild("SmallMoveVel"):Destroy()
end
if hum.FloorMaterial ~= Enum.Material.Air then
local vel = Instance.new("BodyVelocity")
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = enemyHRP
vel.Velocity = Vector3.new(1,1,1) * hrp.CFrame.LookVector * 5
vel.Name = "SmallMoveVel"
Debris:AddItem(vel,.3)
enemyHRP.CFrame = CFrame.lookAt(enemyHRP.Position, hrp.Position)
else
local vel = Instance.new("BodyVelocity")
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = enemyHRP
vel.Velocity = Vector3.new(1,1,1) * hrp.CFrame.LookVector * 5
vel.Name = "SmallMoveVel"
Debris:AddItem(vel,.5)
end
end
local function HitEffects(enemyHRP, amount)
local Atttachy = BloodHit:Clone()
Atttachy.Parent = enemyHRP
Atttachy.Blood:Emit(amount)
Atttachy.Blood2:Emit(amount)
Atttachy.Blood3:Emit(amount)
Debris:AddItem(Atttachy,2)
end
local function HitHighlight(enemy)
local highlight = Instance.new("Highlight")
highlight.Parent = enemy
highlight.DepthMode = Enum.HighlightDepthMode.Occluded
highlight.FillTransparency = 0
highlight.OutlineTransparency = 0
highlight.OutlineColor = Color3.fromRGB(85, 0, 0)
Debris:AddItem(highlight, .5)
local HighlightTweenInfo = {.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false}
local TweenGoal1 = {FillTransparency = 1, OutlineTransparency = 1}
local enemyHitTween = Tween.Tween(highlight, HighlightTweenInfo, TweenGoal1)
end
local function HitStuff(player, HumanoidRootPart, enemychar, enemyhum, hitbox)
PlayersHit[enemychar] = true
Comboing = true
DamageIndicatorModule.show(enemychar, BasicDamage)
enemyhum:TakeDamage(BasicDamage)
local Hitty = HitSound:Clone()
Hitty.Parent = HumanoidRootPart
Hitty:Play()
Debris:AddItem(Hitty,2)
enemychar.Values.Stunned.Value = true
enemyhum.WalkSpeed = 0
enemyhum.JumpHeight = 0
local ui = StunnedGui:Clone()
ui.Parent = enemychar.Head
Debris:AddItem(ui,BasicStun)
task.spawn(function()
task.wait(HitboxStayTime)
PlayersHit[enemychar] = nil
task.wait(.1)
Comboing = false
end)
task.wait(BasicStun)
if enemychar.Values.Stunned.Value == true and Comboing == false then
enemyhum.WalkSpeed = 16
enemyhum.JumpHeight = 7.2
enemychar.Values.Stunned.Value = false
elseif Comboing == true then
task.wait(.2)
enemyhum.WalkSpeed = 16
enemyhum.JumpHeight = 7.2
enemychar.Values.Stunned.Value = false
end
end
local function NormalBlock(Character, hit)
PlayersHit[hit.Parent] = true
local Hitty = BlockSound:Clone()
Hitty.Parent = Character.HumanoidRootPart
Hitty:Play()
game.Debris:AddItem(Hitty,2)
local enemyHum = hit.Parent:FindFirstChild("Humanoid")
local HitAnimation = enemyHum:LoadAnimation(Blocked)
HitAnimation:Play()
task.wait(.3)
PlayersHit[hit.Parent] = nil
end
local function spawnRocksSlam(head, char)
local Size = Vector3.new(1,1,1)
-- Ground spawn --
local Distance = 3
local LifeTime = 4
local RocksAmount = 8
-- Rock Flying --
local Height = 100
local NumberOfRocks = 5
RockModule.Ground(head.Position, Distance, Size,{char, head.Parent}, RocksAmount, false, LifeTime)
local RockSound = SoundFolder.Rock:Clone()
RockSound.Parent = head
RockSound:Play()
Debris:AddItem(RockSound,2)
end
local function NormalPlayerPunch(char, hrp, hum)
local Swingy = PunchSwing:Clone()
Swingy.Parent = hrp
Swingy:Play()
Debris:AddItem(Swingy,2)
local hitbox = Instance.new("Part", char)
hitbox.Anchored = false
hitbox.CanCollide = false
hitbox.Size = hrp.Size * 2
hitbox.CFrame = hrp.CFrame * CFrame.new(0, 0, -2.5)
hitbox.Transparency = .9
Debris:AddItem(hitbox, HitboxStayTime)
local hitboxWeld = Instance.new("ManualWeld")
hitboxWeld.Name = "HitboxWeld"
hitboxWeld.Part0 = hitbox
hitboxWeld.Part1 = hrp
hitboxWeld.C0 = hitbox.CFrame:ToObjectSpace(hrp.CFrame)
hitboxWeld.Parent = hitbox
hum.WalkSpeed = 6
hum.JumpHeight = 0
return hitbox
end
local function ResetPlrFunction(hum)
task.wait(ResetPlr)
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
end
function GetAnimations(Player,AnimationsFolder)
if AnimationsFolder == nil then return nil end
local Animations = {}
for i = 1, #AnimationsFolder:GetChildren() do
table.insert(Animations,AnimationsFolder:GetChildren()[i].Name)
Animations[AnimationsFolder:GetChildren()[i].Name] = Player.Character.Humanoid:LoadAnimation(AnimationsFolder:GetChildren()[i])
end
return Animations
end
------- Functions -------
PunchRemote.OnServerEvent:Connect(function(player, Combo)
local Character = player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Animator = Humanoid:WaitForChild("Animator")
local Animations = GetAnimations(player, AnimationsFolder.Player)
if Combo == 1 then ---- the first Punch
Animations["1"]:Play()
NormalPlayerPunch(Character, HumanoidRootPart, Humanoid)
local hitbox = NormalPlayerPunch(Character, HumanoidRootPart, Humanoid)
task.wait(HitAfter - 0.05)
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not hit:IsDescendantOf(Character) then
if hit.Parent.Values.Iframes.Value == false and PlayersHit[hit.Parent] == nil and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
if hit.Parent.Values.Blocking.Value == false then
local enemyHum = hit.Parent:FindFirstChild("Humanoid")
local enemyHRP = hit.Parent:FindFirstChild("HumanoidRootPart")
local HitAnimation = enemyHum.Animator:LoadAnimation(LeftHit)
HitAnimation:Play()
HitEffects(enemyHRP, 15)
HitHighlight(hit.Parent)
NormalPlayerVelocity(Character,Humanoid,HumanoidRootPart)
NormalEnemyVelocity(Character,Humanoid,HumanoidRootPart, enemyHRP)
HitStuff(player, HumanoidRootPart, hit.Parent, enemyHum, hitbox)
else
coroutine.wrap(NormalBlock)(Character, hit)
end
end
end
end
end)
ResetPlrFunction(Humanoid)
end -- last end for Combo == 1
if Combo == 2 then ---- the second Punch
Animations["2"]:Play()
NormalPlayerPunch(Character, HumanoidRootPart, Humanoid)
local hitbox = NormalPlayerPunch(Character, HumanoidRootPart, Humanoid)
task.wait(HitAfter)
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not hit:IsDescendantOf(Character) then
if hit.Parent.Values.Iframes.Value == false and PlayersHit[hit.Parent] == nil and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
if hit.Parent.Values.Blocking.Value == false then
local enemyHum = hit.Parent:FindFirstChild("Humanoid")
local enemyHRP = hit.Parent:FindFirstChild("HumanoidRootPart")
local HitAnimation = enemyHum.Animator:LoadAnimation(LeftHit)
HitAnimation:Play()
HitEffects(enemyHRP, 15)
HitHighlight(hit.Parent)
NormalPlayerVelocity(Character,Humanoid,HumanoidRootPart)
NormalEnemyVelocity(Character,Humanoid,HumanoidRootPart, enemyHRP)
HitStuff(player, HumanoidRootPart, hit.Parent, enemyHum, hitbox)
else
coroutine.wrap(NormalBlock)(Character, hit)
end
end
end
end
end)
ResetPlrFunction(Humanoid)
end -- last end for Combo == 2
if Combo == 3 then ---- the third Punch
Animations["3"]:Play()
NormalPlayerPunch(Character, HumanoidRootPart, Humanoid)
local hitbox = NormalPlayerPunch(Character, HumanoidRootPart, Humanoid)
task.wait(HitAfter)
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not hit:IsDescendantOf(Character) then
if hit.Parent.Values.Iframes.Value == false and PlayersHit[hit.Parent] == nil and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
if hit.Parent.Values.Blocking.Value == false then
local enemyHum = hit.Parent:FindFirstChild("Humanoid")
local enemyHRP = hit.Parent:FindFirstChild("HumanoidRootPart")
local HitAnimation = enemyHum.Animator:LoadAnimation(LeftHit)
HitAnimation:Play()
HitEffects(enemyHRP, 15)
HitHighlight(hit.Parent)
NormalPlayerVelocity(Character,Humanoid,HumanoidRootPart)
NormalEnemyVelocity(Character,Humanoid,HumanoidRootPart, enemyHRP)
HitStuff(player, HumanoidRootPart, hit.Parent, enemyHum, hitbox)
else
coroutine.wrap(NormalBlock)(Character, hit)
end
end
end
end
end)
ResetPlrFunction(Humanoid)
end -- last end for Combo == 2
if Combo == 4 then ---- the fourth Punch
Animations["4"]:Play()
NormalPlayerPunch(Character, HumanoidRootPart, Humanoid)
local hitbox = NormalPlayerPunch(Character, HumanoidRootPart, Humanoid)
task.wait(HitAfter)
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not hit:IsDescendantOf(Character) then
if hit.Parent.Values.Iframes.Value == false and PlayersHit[hit.Parent] == nil and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
if hit.Parent.Values.Blocking.Value == false then
local enemyHum = hit.Parent:FindFirstChild("Humanoid")
local enemyHRP = hit.Parent:FindFirstChild("HumanoidRootPart")
local HitAnimation = enemyHum.Animator:LoadAnimation(LeftHit)
HitAnimation:Play()
HitEffects(enemyHRP, 15)
HitHighlight(hit.Parent)
NormalPlayerVelocity(Character,Humanoid,HumanoidRootPart)
NormalEnemyVelocity(Character,Humanoid,HumanoidRootPart, enemyHRP)
HitStuff(player, HumanoidRootPart, hit.Parent, enemyHum, hitbox)
else
coroutine.wrap(NormalBlock)(Character, hit)
end
end
end
end
end)
ResetPlrFunction(Humanoid)
end -- last end for Combo == 4
if Combo == 5 then ---- the final Punch
CanHit = true
local Swingy = PunchSwing:Clone()
Swingy.Parent = HumanoidRootPart
Swingy:Play()
Debris:AddItem(Swingy,2)
---- animation
if Humanoid.FloorMaterial ~= Enum.Material.Air then
Animations["Final"]:Play()
else
Animations["DownSlam"]:Play()
end
local hitbox = Instance.new("Part", Character)
hitbox.Anchored = false
hitbox.CanCollide = false
hitbox.Size = HumanoidRootPart.Size * 2.5
hitbox.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, -2.5)
hitbox.Transparency = 1
Debris:AddItem(hitbox, HitboxStayTime)
local hitboxWeld = Instance.new("ManualWeld")
hitboxWeld.Name = "HitboxWeld"
hitboxWeld.Part0 = hitbox
hitboxWeld.Part1 = HumanoidRootPart
hitboxWeld.C0 = hitbox.CFrame:ToObjectSpace(HumanoidRootPart.CFrame)
hitboxWeld.Parent = hitbox
Humanoid.WalkSpeed = 0
Humanoid.JumpHeight = 0
Humanoid.AutoRotate = false
Character.Values.Stunned.Value = true
Character.Values.Iframes.Value = true
task.wait(HitAfter)
hitbox.Touched:Connect(function(hit)
if CanHit == false then return end
if hit.Parent:FindFirstChild("Humanoid") then
if not hit:IsDescendantOf(Character) then
if hit.Parent.Values.Iframes.Value == false and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
if hit.Parent.Values.Blocking.Value == false then
CanHit = false
local enemy = hit.Parent
local enemyHum = hit.Parent:FindFirstChild("Humanoid")
enemyHum:TakeDamage(FinalDamage)
local enemyHRP = hit.Parent:FindFirstChild("HumanoidRootPart")
DamageIndicatorModule.show(enemy, FinalDamage)
enemyHRP.CFrame = HumanoidRootPart.CFrame*CFrame.new(0,0,-3)
enemyHRP.CFrame = CFrame.lookAt(enemyHRP.Position, HumanoidRootPart.Position)
local HitAnimation = enemyHum.Animator:LoadAnimation(KnockBack)
HitAnimation:Play()
local Shakes = Shake:Clone()
Shakes.Parent = Character
Shakes.Disabled = false
Debris:AddItem(Shakes,.55)
local blurSize = 20
local blurSpeed = 1
PunchRemote:FireClient(player, blurSize, blurSpeed)
HitEffects(enemy.Head, 50)
local highlight = Instance.new("Highlight")
highlight.Parent = enemy
highlight.DepthMode = Enum.HighlightDepthMode.Occluded
highlight.FillTransparency = 0
highlight.FillColor = Color3.fromRGB(255, 255, 255)
highlight.OutlineTransparency = 0
local HighlightTweenInfo = {FinalStun + .5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false}
local TweenGoal1 = {FillTransparency = 1, OutlineTransparency = 1}
local enemyHitTween = Tween.Tween(highlight, HighlightTweenInfo, TweenGoal1)
hit.Parent.Values.Stunned.Value = true
enemy.Values.Iframes.Value = true
enemyHum.WalkSpeed = 0
enemyHum.JumpHeight = 0
enemyHum.AutoRotate = false
local ui = StunnedGui:Clone()
ui.Parent = enemy.Head
Debris:AddItem(ui,FinalStun)
local Hitty = Heavy:Clone()
Hitty.Parent = HumanoidRootPart
Hitty:Play()
Debris:AddItem(Hitty,2)
if Humanoid.FloorMaterial ~= Enum.Material.Air then
task.spawn(function()
task.wait(.7)
spawnRocksSlam(enemy.Head, Character)
if game:GetService("Players"):FindFirstChild(enemy.Name) then --if the enemy is a plr then create a blood particle on his screen
local enemyPlr = game:GetService("Players"):GetPlayerFromCharacter(enemy)
local blood = enemyPlr.PlayerGui.ScreenEffects.Blood1
local r = Random.new()
local r2 = math.random(0,360)
blood["Big Blood Damage 4"]:Play()
blood.ImageTransparency = 0
blood.Position = UDim2.new(r:NextNumber(0,.8),0,r:NextNumber(0,.8),0)
blood.Rotation = r2
blood.Visible = true
while CanHit == false do
hit.Parent.Values.Stunned.Value = true
task.wait()
end
task.wait(3)
TS:Create(blood, TweenInfo.new(2), {ImageTransparency = 1}):Play()
blood:TweenPosition(blood.Position + UDim2.new(0,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 3)
end
end)
else
local vel = Instance.new("BodyVelocity")
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = enemyHRP
vel.Velocity = Vector3.new(1,-3,1.5) * Character:WaitForChild("HumanoidRootPart").CFrame.LookVector * 40
vel.Name = "SmallMoveVel"
Debris:AddItem(vel,.3)
local vel = Instance.new("BodyVelocity")
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = HumanoidRootPart
vel.Velocity = Vector3.new(1,2,-1) * Character:WaitForChild("HumanoidRootPart").CFrame.LookVector * 3
vel.Name = "SmallMoveVel"
Debris:AddItem(vel,.1)
end
task.wait(FinalStun)
if hit.Parent.Values.Stunned.Value == true then
enemyHum.WalkSpeed = 16
enemyHum.JumpHeight = 7.2
enemy.Values.Stunned.Value = false
enemyHum.AutoRotate = true
end
CanHit = false
hitbox:Destroy()
task.wait(.5)
enemy.Values.Iframes.Value = false
else
local enemy = hit.Parent
local enemyHum = enemy:FindFirstChild("Humanoid")
local BreakHighlight = Instance.new("Highlight", enemy)
BreakHighlight.DepthMode = Enum.HighlightDepthMode.Occluded
Debris:AddItem(BreakHighlight,GuardBroken)
enemyHum.WalkSpeed = 0
enemyHum.JumpHeight = 0
enemyHum.AutoRotate = false
local Hitty = BlockBreakSound:Clone()
Hitty.Parent = Character.HumanoidRootPart
Hitty:Play()
game.Debris:AddItem(Hitty,2)
enemy.Values.Blocking.Value = false
enemy.Values.Stunned.Value = true
CanHit = false
local ui = StunnedGui:Clone()
ui.Parent = enemy.Head
game.Debris:AddItem(ui,GuardBroken)
local HitAnimation = enemyHum:LoadAnimation(Break)
HitAnimation:Play()
local Atttachy = AttachmentBreak:Clone()
Atttachy.Parent = enemy.HumanoidRootPart
Atttachy.Radial:Emit(1)
Atttachy.CenterPiece:Emit(3)
Atttachy.Sparks:Emit(30)
Atttachy.Crack:Emit(1)
Atttachy.Shield:Emit(30)
game.Debris:AddItem(Atttachy,2)
Humanoid.WalkSpeed = 16
Humanoid.JumpHeight = 7.2
Humanoid.AutoRotate = true
Character.Values.Stunned.Value = false
Character.Values.Iframes.Value = false
task.wait(GuardBroken)
enemy.Values.Stunned.Value = false
enemyHum.WalkSpeed = 16
enemyHum.JumpHeight = 7.2
enemyHum.AutoRotate = true
end
end
end
end
end)
task.wait(ResetPlr + 1)
Humanoid.WalkSpeed = 16
Humanoid.JumpHeight = 7.2
Humanoid.AutoRotate = true
Character.Values.Stunned.Value = false
Character.Values.Iframes.Value = false
end -- last end for Combo == 5
end)
I don’t even know if someone wants to read all of that but if yes I appreciate it