Players.ilippo.PlayerGui.ScreenGui.Storage.Script:15:尝试使用“Connect”索引 nil

问题描述 投票:0回答:2




local proximityprompt = game.Workspace.Tycoons.Tycoon.MainItems.Cardboard_Box.Box.ProximityPrompt
local StorageGui = script.Parent
local x = script.Parent.Storage.Frame.X

local Orebuttons = script.Parent.Storage.Frame.Ores:GetChildren()
local OreString = script.Parent.Parent.Sell.Frame.Ore

proximityprompt.Triggered:Connect(function()

    StorageGui.Visible = true
end)
x.MouseButton1Click:Connect(function()
    StorageGui.Visible = false
end)
Orebuttons.MouseButton1Click:Connect(function()
    print("Click")
    OreString.Value = Orebuttons.Name
end)




我不知道我该怎么办 我尝试让文件夹中的所有按钮都可以在 1 行代码中工作,我认为这不会给我带来更多问题

lua roblox
2个回答
0
投票

看起来您正在从

Orebuttons
获取子级,它返回一个数组,然后连接到返回 nil 的子级,因为它是一个数组,而不是您可以连接到的按钮。

您需要循环遍历

Orebuttons
中的每个按钮,然后连接到该按钮。

for _, button: GuiButton in pairs(Orebuttons) do
    if button:IsA("GuiButton") then
        button.MouseButton1Click:Connect(function()
            print("Click")
            OreString.Value = button.Name
        end)
    end
end

此代码遍历

Orebuttons
数组,然后如果子级是
GuiButton
,则将
MouseButton1Click
连接到该按钮。


0
投票

但我不知道为什么矿带没有改变

© www.soinside.com 2019 - 2024. All rights reserved.