【问题标题】:Getting an Object error when attempting to find ID Value in Workspace尝试在工作区中查找 ID 值时出现对象错误
【发布时间】:2020-01-04 14:00:35
【问题描述】:

我正在尝试使用值在工作区中查找对象。 打印值时,它将值“WM830”打印为字符串。 但它没有在工作区中找到模型。

这是代码:

script.Parent.MouseButton1Click:connect(function()
    local busId = script.Parent.Parent.Parent.Car.value
    game.Workspace[busId].Body.Display.maindest.SurfaceGUI.TextLabel.text = "Woop"
end)

这是错误: Players.E_Link.PlayerGui.A-Chassis Interface.NXUI.TextButton.Script:3: bad argument #2 to '?' (string expected, got Object)

【问题讨论】:

  • 原来它使用了错误的值实体。我想念 licked 并且 Roblox 使所有值看起来都一样。

标签: roblox


【解决方案1】:

它可以帮助您尝试将通往 TextLabel 的路径分解成更可靠的块:

script.Parent.Activated:Connect(function()
    -- find the name of the bus for this button
    local busId = script.Parent.Parent.Parent.Car.value
    local bus = game.Workspace:FindFirstChild(busId)

    if bus then
        -- if we find the bus, update the label on the bus
        -- NOTE - IF THIS NEXT LINE FAILS, CONTINUE TO BREAK UP THIS PATH INTO SMALLER PIECES
        local busDestLabel = bus.Body.Display.maindest.SurfaceGUI.TextLabel
        busDestLabel.Text = "Woop"
    else
        -- Couldn't find the bus, check that the bus actually exists in the workspace
        warn("Could not find a bus with id : ", busId)
    end
end)

这样,您的错误消息可能会更接近路径的实际缺失部分。在尝试获取或设置属性之前验证您要使用的零件/模型是否确实存在也是一种很好的做法。

【讨论】:

    猜你喜欢
    • 2023-02-09
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多