Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- local script ---
- local plr = game.Players.LocalPlayer
- local UIS = game:GetService("UserInputService")
- local count = 1
- local db = false -- wether a hit can be perfomed or not
- local animations = script.Animations
- local waitTime = 0.1 -- cooldown between hits
- local maxComboTime = 1.5
- local lastClickTime = 0
- local speedMul = 2.0
- UIS.InputBegan:Connect(function(input , gpe)
- if gpe then return end
- local characterMove -- initializing animation folder and variables for said animations
- local hit1
- local hit2
- local hit3
- local hit4
- if input.UserInputType == Enum.UserInputType.MouseButton1 and plr.Character:GetAttribute("Stun") == false and plr.Character:GetAttribute("IFrame") == false then
- local currentTime = tick()
- local timeSinceLastClick = currentTime - lastClickTime
- lastClickTime = currentTime
- if plr.state["type"].Value == 1 then -- checks if the users "type" is 1 ("refrencing a specific character")
- characterMove = animations.AlastorAnimations
- hit1 = characterMove["1"] -- asign each hit to a specific animation in the characterMove folder
- hit2 = characterMove["2"]
- hit3 = characterMove["1"]
- hit4 = characterMove["2"]
- end
- if db == true then return end -- if db is true then we cannot click
- if timeSinceLastClick > maxComboTime then
- count = 1
- end
- if count == 1 and not db then
- local targetCount = 2
- local humanoid = plr.Character:WaitForChild("Humanoid")
- local animator = humanoid:WaitForChild("Animator")
- local animationTrack = animator:LoadAnimation(hit1)
- animationTrack:Play()
- animationTrack:AdjustSpeed(speedMul)
- animationTrack.KeyframeReached:Connect(function(keyframeName)
- if keyframeName == "Damage" then
- game.ReplicatedStorage.CombatRemote:FireServer(count -1)
- else
- return
- end
- end)
- count = targetCount
- db = true
- task.wait(waitTime) -- setting db to true then waiting to set it to false
- db = false
- elseif count == 2 and not db then
- local targetCount = 3
- local humanoid = plr.Character:WaitForChild("Humanoid")
- local animator = humanoid:WaitForChild("Animator")
- local animationTrack = animator:LoadAnimation(hit2)
- animationTrack:Play()
- animationTrack:AdjustSpeed(speedMul)
- animationTrack.KeyframeReached:Connect(function(keyframeName)
- if keyframeName == "Damage" then
- game.ReplicatedStorage.CombatRemote:FireServer(count -1)
- end
- end)
- count = targetCount
- db = true
- task.wait(waitTime)
- db = false
- elseif count == 3 and not db then
- local targetCount = 4
- local humanoid = plr.Character:WaitForChild("Humanoid")
- local animator = humanoid:WaitForChild("Animator")
- local animationTrack = animator:LoadAnimation(hit3)
- animationTrack:Play()
- animationTrack:AdjustSpeed(speedMul)
- animationTrack.KeyframeReached:Connect(function(keyframeName)
- if keyframeName == "Damage" then
- game.ReplicatedStorage.CombatRemote:FireServer(count -1)
- end
- end)
- count = targetCount
- db = true
- task.wait(waitTime)
- db = false
- elseif count > 3 and not db then
- local humanoid = plr.Character:WaitForChild("Humanoid")
- local animator = humanoid:WaitForChild("Animator")
- local animationTrack = animator:LoadAnimation(hit4)
- animationTrack:Play()
- animationTrack:AdjustSpeed(speedMul)
- animationTrack.KeyframeReached:Connect(function(keyframeName)
- if keyframeName == "Damage" then
- game.ReplicatedStorage.CombatRemote:FireServer(4)
- end
- end)
- count = 1
- db = true
- task.wait(maxComboTime)
- db = false
- end
- end
- end)
- -- server script ---
- local debris = game:GetService("Debris")
- local damage = 1
- local stunTime = 0.8
- local Modules = game:GetService("ServerStorage").Modules
- local RagdollModule = require(Modules.RagDollModule)
- local ragTime = 2
- local reTime = 5
- local userInputService = game:GetService("UserInputService")
- game.ReplicatedStorage.CombatRemote.OnServerEvent:Connect(function(player, count)
- local TBL = {player.Name,count}
- local miss = game.ServerStorage.Sounds["Punch Swing "]:Clone()
- miss.Parent = player.Character
- miss:Play()
- debris:AddItem(miss,3)
- local character = player.Character
- character:SetAttribute("Attacking", true)
- if character then
- local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- -- Create the damage box
- local damageBox = Instance.new("Part")
- damageBox.CanTouch = true
- damageBox.Size = Vector3.new(5, 6, 5) -- Adjust the size as needed
- damageBox.Anchored = false
- damageBox.CanCollide = false
- damageBox.Transparency = 0.5
- damageBox.BrickColor = BrickColor.new("Bright red")
- damageBox.Name = "DamageBox"
- damageBox.Parent = game.Workspace
- damageBox.CFrame = humanoidRootPart.CFrame * CFrame.new(0,0,-2.5) -- Adjust the distance in front of the player
- damageBox.Touched:Connect(function(target)
- if target == nil then return end
- if target.Name == "Block" then
- character.Humanoid.AutoRotate = false
- character:SetAttribute("Stun", true)
- task.wait(2)
- character.Humanoid.AutoRotate = true
- character:SetAttribute("Stun",false)
- return
- end
- if target.Parent == nil then return end
- local hum = target.Parent:FindFirstChild("Humanoid")
- if hum and count <= 3 and target.Parent:GetAttribute("IFrame") == false and target.Parent:GetAttribute("Ragdoll") == false then
- if target.Parent ~= player.Character then
- local punch = game.ServerStorage.Sounds:WaitForChild("HitPunch")
- local Pclone = punch:Clone()
- Pclone.Parent = player.Character
- Pclone:Play()
- debris:AddItem(Pclone,3)
- if hum.Health - damage <= 0 and hum.Health > 0 then
- hum:TakeDamage(damage)
- player.leaderstats.kills.Value +=1
- RagdollModule.RagdollCharacter(target.Parent)
- RagdollModule.knockBack(target.Parent, character:WaitForChild("HumanoidRootPart"))
- task.wait(reTime)
- RagdollModule.Unragdoll(target.Parent)
- return
- end
- hum:TakeDamage(damage)
- target.Parent:SetAttribute("Stun", true)
- task.wait(stunTime)
- target.Parent:SetAttribute("Stun", false)
- end
- elseif hum and count > 3 and target.Parent:GetAttribute("IFrame") == false and target.Parent:GetAttribute("Ragdoll") == false then
- if target.Parent ~= player.Character then
- local punch = game.ServerStorage.Sounds:WaitForChild("HitPunch")
- local Pclone = punch:Clone()
- Pclone.Parent = player.Character
- Pclone:Play()
- debris:AddItem(Pclone,3)
- if hum.Health - damage <= 0 and hum.Health > 0 then
- hum:TakeDamage(damage)
- player.leaderstats.kills.Value +=1
- RagdollModule.RagdollCharacter(target.Parent)
- RagdollModule.knockBack(target.Parent, character:WaitForChild("HumanoidRootPart"))
- task.wait(reTime)
- RagdollModule.Unragdoll(target.Parent)
- return
- end
- hum:TakeDamage(damage)
- target.Parent:SetAttribute("Stun", true)
- RagdollModule.RagdollCharacter(target.Parent)
- RagdollModule.knockBack(target.Parent, character:WaitForChild("HumanoidRootPart"))
- task.wait(1)
- target.Parent:SetAttribute("Stun", false)
- task.wait(ragTime -1)
- RagdollModule.Unragdoll(target.Parent)
- end
- else
- return
- end
- end)
- debris:AddItem(damageBox,0.1)
- else
- return
- end
- task.wait(0.5)
- character:SetAttribute("Attacking", false)
- end)
- -- ragdoll module ---
- -- RagdollModule.lua
- local RagdollModule = {}
- function RagdollModule.knockBack(target, attackerHRP)
- local targetHRP = target:WaitForChild("HumanoidRootPart")
- if targetHRP == nil then return end
- -- Calculate the direction from the attacker's HRP to the target's HRP
- local direction = (targetHRP.Position - attackerHRP.Position).Unit * Vector3.new(40,0,40) + Vector3.new(0,40)
- local att = Instance.new("Attachment",targetHRP)
- -- Apply a force to the target's HRP in the calculated direction
- local knockbackForce = Instance.new("LinearVelocity", att)
- knockbackForce.VectorVelocity = direction -- Adjust the force as needed
- knockbackForce.MaxForce = 20000
- knockbackForce.Attachment0 = att
- -- Apply an upward force to put the target in the air
- game.Debris:AddItem(att,0.1)
- end
- function RagdollModule.RagdollCharacter(target)
- if target:GetAttribute("Ragdoll") == true then return end
- target:SetAttribute("Ragdoll", true)
- target:WaitForChild("Humanoid"):ChangeState(Enum.HumanoidStateType.Physics)
- -- Check if the target has a Humanoid
- local humanoid = target:FindFirstChildOfClass("Humanoid")
- if not humanoid then
- return
- end
- for i, joint in pairs(target:GetDescendants())do
- if joint:IsA('Motor6D') then
- local socket = Instance.new("BallSocketConstraint", joint.Parent)
- local att0 = Instance.new('Attachment', joint.Part0)
- local att1 = Instance.new('Attachment', joint.Part1)
- att0.CFrame = joint.C0
- att1.CFrame = joint.C1
- socket.Attachment0 = att0
- socket.Attachment1 = att1
- socket.TwistLimitsEnabled = true
- socket.LimitsEnabled = true
- joint.Enabled = false
- end
- end
- target.Humanoid.AutoRotate = false
- end
- function RagdollModule.Unragdoll(target)
- if target == nil then return end
- target:SetAttribute("Stun", false)
- target:WaitForChild("Humanoid"):ChangeState(Enum.HumanoidStateType.GettingUp)
- for i, joint in pairs(target:GetDescendants())do
- if joint:IsA("Motor6D") then
- joint.Enabled = true
- elseif joint:IsA("BallSocketConstraint") then
- joint.Enabled = false
- end
- end
- target:SetAttribute("Ragdoll", false)
- target.Humanoid.AutoRotate = true
- end
- return RagdollModule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement