Button GUI商店有多个按钮,装备物品,购买物品,并检查是否已经有物品

Button GUI商店有多个按钮,装备物品,购买物品,并检查是否已经有物品,button,scripting,lua,roblox,Button,Scripting,Lua,Roblox,我发布的代码旨在做三件事: 按下Buy按钮时,将item.DoesOwn.Value设置为true 当item.DoesOwn.Value为true时,使按钮可见 取消装备所有物品,然后在按下装备时装备所选物品 问题:当我单击多个项目按钮,然后单击buyButton时,它会将所有按钮的DoesOwn.Valueproperties设置为true。我一次只想买一件东西,而且只有在它还没有被拥有的情况下。当他们已经拥有一件物品时,一次装备一件物品也是如此 previewBox=script.Pare

我发布的代码旨在做三件事:

  • 按下Buy按钮时,将
    item.DoesOwn.Value
    设置为true
  • item.DoesOwn.Value
    为true时,使按钮可见
  • 取消装备所有物品,然后在按下装备时装备所选物品
  • 问题:当我单击多个项目按钮,然后单击buyButton时,它会将所有按钮的
    DoesOwn.Value
    properties设置为true。我一次只想买一件东西,而且只有在它还没有被拥有的情况下。当他们已经拥有一件物品时,一次装备一件物品也是如此

    previewBox=script.Parent.PreviewImage
    itemLabel=script.Parent.ItemName
    priceLabel=script.Parent.PriceLabel
    
    equipButton=script.Parent.Equip
    buyButton=script.Parent.Buy
    
    knifeItems=script.Parent.KnifeFrame:GetChildren()
    
    function checkKnifeItems(button,buttons)
        previewBox.Image=button.Image
        itemLabel.Text=button.Name
    
        if button.DoesOwn.Value == true and button.Equipped.Value == false then 
    
            priceLabel.Visible=false
            equipButton.Visible=true
            equipButton.MouseButton1Down:connect(function()
                for i, v in pairs(buttons) do
                    buttons[i].Equipped.Value=false
                end
    
                button.Equipped.Value=true
                equipButton.Visible=false
                button.BackgroundColor3=Color3.new(0/277, 255/277, 127/277)
            end)
        elseif button.DoesOwn.Value == false then
            equipButton.Visible=false
            buyButton.Visible=true
            buyButton.MouseButton1Down:connect(function()
                button.DoesOwn.Value=true
                button.BackgroundColor3=Color3.new(255/277, 255/277, 255/277)
                buyButton.Visible=false
            end)
        end
    end
    
    for i,v in pairs (knifeItems) do
        v.MouseButton1Down:connect(function()checkKnifeItems(v,knifeItems) end)
    end
    

    没关系,我自己解决了,这是一个简单的问题。

    没关系,我自己解决了,这是一个简单的问题。

    是的,我同意这是一个简单的问题。如果你投入几分钟的时间,你可以很容易地修复它。我知道roblox上有一个很好的程序员,如果你想知道他的用户名:person299是的,我同意这是一个简单的问题。如果你投入几分钟的时间,你可以很容易地修复它。我知道roblox上有一个很好的编码员,如果你想知道他的用户名:person299

    缺少缩进使得代码很难阅读。如果,缩进
    的内容如何<代码>结束
    块?(加上
    for
    ..
    do
    ..
    end
    等等)。感谢你修复了缩进,我是这个网站的新手,但是你知道这个代码有什么问题吗?缩进的缺失使得代码很难阅读。如果,缩进
    的内容如何<代码>结束
    块?(加上
    for
    ..
    do
    ..
    end
    等等)。谢谢你修复了缩进,我是这个网站的新手,但是你知道这个代码有什么问题吗?