首页 > 解决方案 > SprintingAnimation:19: 预期 ')' (在第 29 列关闭 '('),得到 ','

问题描述

在我的游戏中,我制作了一个可以冲刺的功能。我已经将脚本的动画部分与主要的冲刺部分分开。我收到错误消息"Workspace.Vlo_tz.SprintingAnimation:19: Expected ')' (to close '(' at column 29), got ','". 此代码用于角色和冲刺栏的动画

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local players = game:GetService("Players")
local stamina = players.LocalPlayer.PlayerGui.StaminaHealth.MainFrame.Stamina

UIS.InputBegan:connect(function(input)
    local humanoid = Player.Character.Humanoid
    if input.KeyCode == Enum.KeyCode.LeftShift and humanoid:GetState() == Enum.HumanoidStateType.RunningNoPhysics and humanoid.MoveDirection.Magnitude > 0 then
        local Anim = Instance.new('Animation')
        Anim.AnimationId = 'rbxassetid://05168161960'
        PlayAnim = Character.Humanoid:LoadAnimation(Anim)
        PlayAnim:Play()

        while true do
            wait(0.05)

            if stamina.Position <= (-0.343, 0, 0.274, 0) then
                stamina.Position = UDim2.new(-0.343, 0, 0, 0)
            else
                stamina.Position = stamina.Position - UDim2.new(0.01, 0, 0, 0)
            end
        end
    end
end)

UIS.InputEnded:connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        PlayAnim:Stop()

        while true do
            wait(0.005)

            if stamina.Position >= (0.487, 0, 0.274, 0) then
                stamina.Position = UDim2.new(0.487, 0, 0, 0)
            else
                stamina.Position = stamina.Position + UDim2.new(0.01, 0, 0, 0)
            end
        end
    end
end)

local humanoid = Player.Character.Humanoid
if humanoid.MoveDirection.Magnitude == 0 then
    PlayAnim:Stop()

    while true do
        wait(0.005)

        if stamina.Position >= (0.487, 0, 0.274, 0) then
            stamina.Position = UDim2.new(0.487, 0, 0, 0)
        else
            stamina.Position = stamina.Position + UDim2.new(0.01, 0, 0, 0)
        end
    end
end

标签: luaroblox

解决方案


第 19 行是这样的:if stamina.Position <= (-0.343, 0, 0.274, 0) then

您在几个不同的地方进行了此检查,但这不是有效的 lua,您无法像这样比较 UDim2 值。您必须单独检查这些值。

local isLessThanX = stamina.Position.X.Scale <= -0.343
local isLessThanY = stamina.Position.Y.Scale <= 0.274
if isLessThanX and isLessThanY then

推荐阅读