Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local tool = script.Parent
- local punchEvent = tool:WaitForChild("PunchEvent")
- -- ВСТАВЬ СЮДА ID СВОЕЙ АНИМАЦИИ
- local ANIMATION_ID = "rbxassetid://123456789012345"
- -- Перезарядка удара
- local COOLDOWN = 0.65
- local lastPunch = 0
- local animationTrack = nil
- -- Создаём анимацию
- local punchAnimation = Instance.new("Animation")
- punchAnimation.AnimationId = ANIMATION_ID
- -- Загружаем анимацию персонажа
- local function loadAnimation()
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local animator = humanoid:WaitForChild("Animator")
- local success, result = pcall(function()
- return animator:LoadAnimation(punchAnimation)
- end)
- if not success then
- warn("Не удалось загрузить анимацию:", result)
- return
- end
- animationTrack = result
- animationTrack.Priority = Enum.AnimationPriority.Action
- animationTrack.Looped = false
- end
- -- Экипировка оружия
- tool.Equipped:Connect(function()
- loadAnimation()
- end)
- -- Нажатие ЛКМ
- tool.Activated:Connect(function()
- local now = os.clock()
- if now - lastPunch < COOLDOWN then
- return
- end
- lastPunch = now
- -- Загружаем анимацию, если необходимо
- if not animationTrack then
- loadAnimation()
- end
- -- Проигрываем замах
- if animationTrack then
- if animationTrack.IsPlaying then
- animationTrack:Stop(0.03)
- end
- animationTrack:Play(0.04, 1, 1)
- end
- -- Отправляем запрос серверу
- punchEvent:FireServer()
- end)
- -- Снятие перчаток
- tool.Unequipped:Connect(function()
- if animationTrack then
- animationTrack:Stop(0.1)
- animationTrack = nil
- end
- end)
- -- Сбрасываем старую анимацию после перерождения
- player.CharacterAdded:Connect(function()
- animationTrack = nil
- end)
Advertisement
Add Comment
Please, Sign In to add comment