Lua
local Tool = script.Parent
local Damage = 25 -- Урон от меча
local Cooldown = 1 -- Время перезарядки в секундах
local canAttack = true
Tool.RemoteEvent.OnServerEvent:Connect(function(player)
if not canAttack then return end
local character = player.Character
if not character then return end
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then return end
local animation = script.Animation
local animTrack = humanoid:LoadAnimation(animation)
-- Начало атаки
canAttack = false
animTrack:Play()
Tool.Value.Value = true
-- Проверка на попадание
local handle = Tool:FindFirstChild("Handle")
if handle then
local hitbox = handle:FindFirstChild("HitBox") or handle
local touching = hitbox:GetTouchingParts()
for _, part in pairs(touching) do
local victimChar = part:FindFirstAncestorWhichIsA("Model")
if victimChar then
local victimHumanoid = victimChar:FindFirstChild("Humanoid")
if victimHumanoid and victimChar ~= character then
victimHumanoid:TakeDamage(Damage)
end
end
end
end
-- Окончание атаки и перезарядка
task.wait(Cooldown)
animTrack:Stop()
Tool.Value.Value = false
canAttack = true
end)
script.Parent.RemoteEvent.OnServerEvent:Connect(function()
local humanoid = script.Parent.Parent:FindFirstChildOfClass("Humanoid")
local attack = humanoid:LoadAnimation(script.Animation)
if canAttack then
attack:Play()
canAttack = false
script.Parent.Value.Value = true
task.wait(1) -- Заменяем wait() на task.wait()
attack:Stop()
canAttack = true
script.Parent.Value.Value = false
end
end)