Lua代码报错:应为')'闭合第38行'(', 求大亨游戏修复方案
Lua语法错误修复:应为')'以闭合'(', 却得到'.'
错误原因
这个语法错误的核心问题是匿名函数定义时括号未正确闭合。在创建协程的代码块中,coroutine.create(function(这一行只写了左括号(,却没有补全右括号)就直接开始编写函数体,Lua解析器无法识别后续代码里的.(v.ButtonPart.Transparency中的点),因此抛出了该错误。
修复后的代码
for i, v in pairs(Buttons:GetChildren()) do local NewItem = BoughtItems:FindFirstChild(v.Item.Value) -- 注意:Roblox属性首字母大写,修正为Value if NewItem ~= nil then Items[NewItem.Name] = NewItem:Clone() NewItem:Destroy() else v.ButtonPart.Transparency = 1 v.ButtonPart.CanCollide = false v.ButtonPart.BillBoardGui.Frame.Visible = false end if v:FindFirstChild("Dependency") then -- 修复:补上函数定义的闭合括号) coroutine.resume(coroutine.create(function() v.ButtonPart.Transparency = 1 v.ButtonPart.CanCollide = false v.ButtonPart.BillBoardGui.Frame.Visible = false if BoughtItems:WaitForChild(v.Dependency.Value, 100000) then v.ButtonPart.Transparency = 0 v.ButtonPart.CanCollide = true v.ButtonPart.BillBoardGui.Frame.Visible = true end end)) end v.ButtonPart.Touched:Connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) if Values.OwnerValue.Value == Player then if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then if Player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then Player.leaderstats.Cash.Value -= v.Price.Value Items[v.Item.Value].Parent = BoughtItems v:Destroy() end end end end end) end
额外注意事项
- Roblox中的对象属性首字母默认大写(如
Value而非value),代码中v.Item.value建议修正为v.Item.Value,避免后续出现找不到属性的隐性问题。 - 无参数的匿名函数定义时,直接写
function()即可,不要留空括号不闭合。
内容的提问来源于stack exchange,提问作者Blox Kid
相关产品推荐
相关产品推荐

