Lua 当没有显示错误时,如何修复我的战斗脚本?

Lua 当没有显示错误时,如何修复我的战斗脚本?,lua,roblox,Lua,Roblox,我已经创建了这个脚本,希望创建一个战斗系统,可以在一个按钮中播放多个动画;但是,当我将它们放在脚本的灯光攻击部分时,动画将不会播放,但我的代码中没有错误 我尝试过重新组织,使用实际的动画ID,更改变量名,等等 local Player = game.Players.LocalPlayer local Character = script.Parent local Humanoid = Character.Humanoid AnimationId1 = "rbxassetid://20467878

我已经创建了这个脚本,希望创建一个战斗系统,可以在一个按钮中播放多个动画;但是,当我将它们放在脚本的灯光攻击部分时,动画将不会播放,但我的代码中没有错误

我尝试过重新组织,使用实际的动画ID,更改变量名,等等

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)

这个脚本的阻塞部分工作得很好,但是,当我尝试使用light attack部分时,它不起作用。

在light attack函数中,
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)

当你说,光攻击不起作用时,你期望发生什么,实际发生什么?当我按下按钮(“U”)时,没有任何动画播放。但我没有错误。它不会播放任何东西,所以什么也不会发生。您是否尝试过打印if语句的值,或者打印if语句的第一行,如
U。播放动画
,这些通常是我在TS代码中的第一步,这些代码不能按预期工作,但会编译/运行。感谢您的推荐。它一直工作到“如果v==1,那么”。似乎存在某种类型的断开连接。您的值
v
可能是
“1”
,而不是
1
?您可以通过执行
键入(v)
来检查这一点,并查看您是否得到
编号
字符串
。谢谢,这对您帮助很大!但是它似乎遇到了另一个问题,它循环第二个动画,直到你垃圾邮件“U”,然后不会再播放。