You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 21:35:22