I want to deal damage to the humanoid when the PunchAnim1 or PunchAnim2 Is played but it doesnt seem to deal damage and no errors show up
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local RunServ = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
--if not Char.Parent then Char = Player.CharacterAdded:Wait() end
local Hum = Char:WaitForChild("Humanoid")
local HRP = Char:WaitForChild("HumanoidRootPart")
local Animator = Char:WaitForChild("Humanoid"):WaitForChild("Animator")
local Zone1Parts = game.Workspace.Map.Zone1.Model
local Mouse = Player:GetMouse()
local tool = script.Parent
local Storage = RS.Storage
local AnimationFolder = Storage.Animations
local PunchAnim1 = Hum:LoadAnimation(AnimationFolder.FloorPunch1)
local PunchAnim2 = Hum:LoadAnimation(AnimationFolder.FloorPunch2)
local Debounce = false
local lastAttackTime = 0
local comboStep = 0
local cd = .5
local function TakeDamage(humanoid, damage)
local health = humanoid.Health
print("Current health:", health)
health = health - damage
print("New health:", health)
humanoid.Health = health
end
local function AttackPart(part)
print("Attacking part:", part)
if part:IsDescendantOf(Zone1Parts) then
local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
print("Dealing damage to humanoid:", humanoid)
TakeDamage(humanoid, 10)
end
end
end
local function CheckKeyframeReached(keyframe)
print("Keyframe reached:", keyframe)
if keyframe == "Hit" then
local touchingParts = HRP:GetTouchingParts()
if #touchingParts > 0 then -- Check if the character is touching any parts
local hitPart = touchingParts[1]
AttackPart(hitPart)
end
end
end
PunchAnim1.KeyframeReached:Connect(CheckKeyframeReached)
PunchAnim2.KeyframeReached:Connect(CheckKeyframeReached)
tool.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
if Debounce == false then
Debounce = true
local currentTime = tick()
if currentTime - lastAttackTime <= 0.7 and comboStep == 1 then -- Check if it's a combo and on the second step
PunchAnim1:Play()
comboStep = 0 -- Reset the combo
wait(cd)
Debounce = false
elseif currentTime - lastAttackTime <= 0.7 then -- Otherwise start the combo
PunchAnim2:Play()
comboStep = 1 -- Set the combo to the second step
wait(cd)
Debounce = false
else -- Otherwise play the first punch
PunchAnim1:Play()
comboStep = 0 -- Reset the combo
wait(cd)
Debounce = false
end
lastAttackTime = currentTime
end
end)
end)
tool.Unequipped:Connect(function()
print("Tool unequipped")
end)