lua - 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
解决方案
第 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
推荐阅读
- python - 将数据框从 float64 更改为 float128 Python
- haskell - 使用 monadtransformer 复制 liftIO 的概念
- kubernetes - 在 Kubernetes 中使用 Hazelcast 的 Sonatype Nexus HA
- python - 我是初学者,我正在努力学习学习 python,所以我对这个 python 代码有问题(if else 语句)
- flutter - 颤振 dio 中的等效代码与 android 改造 @body 相比是什么?
- javascript - 在谷歌图表中按时间过滤
- javascript - 同上 HTTP API 服务器发送事件 CORS 错误
- java - .sendKeys() 方法在我尝试设置值时不起作用
- java - 在 JUnit 5 中使用 spring 项目测试删除方法得到“未指定类型 [long] 的参数名称”错误
- elasticsearch - 为什么lucene的段是不可变的