Как исправить мой боевой скрипт, когда ошибки не отображаются? - PullRequest
1 голос
/ 25 июня 2019

Я создал этот скрипт в надежде создать боевую систему, которая может проигрывать несколько анимаций за одну кнопку;однако, когда я помещаю их в раздел легкой атаки скрипта, анимации не воспроизводятся, но у меня нет ошибок в коде.

Я попытался реорганизовать, используя реальные идентификаторы анимации, изменив имена переменныхи т. д.

local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character.Humanoid
AnimationId1 = "rbxassetid://2046787868"
AnimationId2 = "rbxassetid://2046881922"
AnimationId3 = "rbxassetid://"
AnimationId4 = "rbxassetid://2048242167"
Debounce = true
local Key = 'U'
local Key2 = 'I'
local Key3 = 'O'
local Key4 = 'P'

local UserInputService = game:GetService("UserInputService")

--Animation for the Light attk combo sequence.
UserInputService.InputBegan:connect(function(Input, IsTyping)
    for i, v in pairs(game.Players:GetChildren()) do
        if Input.KeyCode == Enum.KeyCode[Key] then
            local Animation = Instance.new("Animation")
            Animation.AnimationId = AnimationId1, AnimationId2
            local LoadAnimation = Humanoid:LoadAnimation(Animation)
            if v == 1 then
                LoadAnimation:Play(AnimationId1)
            elseif v == 2 then
                LoadAnimation:Play(AnimationId2)
            end
        end
    end
end)



--Animation for the Blocking sequence.
UserInputService.InputBegan:connect(function(Input, IsTyping)
    if IsTyping then return end
    if Input.KeyCode == Enum.KeyCode[Key4] and Debounce then
        Debounce = false
        local Animation = Instance.new("Animation")
        Animation.AnimationId = AnimationId4
        local LoadAnimation = Humanoid:LoadAnimation(Animation)
        LoadAnimation:Play()
        wait(.5)
        LoadAnimation:Stop()
        Debounce = true
    end
end)

Блокирующая часть этого скрипта работает отлично, однако, когда я пытаюсь использовать секцию легкой атаки, она не работает.

1 Ответ

1 голос
/ 26 июня 2019

В вашей функции легкой атаки v является игроком объектом. Поэтому любая проверка, например v == 1 или v == 2, не будет выполнена, потому что это неправильный тип. Также не имеет смысла перебирать всех игроков, когда они нажимают кнопку «U».

Вы можете заставить его воспроизводить анимацию так же, как вы это делали с кодом блокировки анимации.

-- make a counter to help decide which animation to play
local swingCount = 0
local currentSwingAnimation    

--Animation for the Light attack combo sequence.
UserInputService.InputBegan:connect(function(Input, IsTyping)
    if IsTyping then return end

    if Input.KeyCode == Enum.KeyCode[Key] then
        swingCount = swingCount + 1

        -- cancel any animation currently playing
        if currentSwingAnimation then
            currentSwingAnimation:Stop()
            currentSwingAnimation = nil
        end

        if swingCount == 1 then
            -- play the first animation
            local Animation = Instance.new("Animation")
            Animation.AnimationId = AnimationId1
            currentSwingAnimation = Humanoid:LoadAnimation(Animation)
            currentSwingAnimation.Looped = false
            currentSwingAnimation:Play()

        elseif swingCount == 2 then
            -- play the second swing animation
            local Animation = Instance.new("Animation")
            Animation.AnimationId = AnimationId2
            currentSwingAnimation = Humanoid:LoadAnimation(Animation)
            currentSwingAnimation.Looped = false
            currentSwingAnimation:Play()

            -- reset the swing counter to start the combo over
            swingCount = 0
        end
    end
end)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...