Roblox:帽子库存系统问题

时间:2019-07-14 17:32:51

标签: lua roblox

现在,我有了它,以便当您在商店中购买帽子时,它可以保存到数据存储中,但是它也可以替换您已经戴上并已经保存到数据存储中的帽子。我想要发生的是将其添加到屏幕gui中的玩家清单中。我真的不知道该怎么做。我应该将表添加到数据存储区还是其他内容。

发生这种情况的游戏示例是在SwordBurst中节省了盔甲。同样,任何具有宠物收集系统的游戏,我认为也会运行相同的代码。

function addhat(player, hat)
    --wait(1)
    local char = player.Character or player.CharacterAdded.Wait()
    print(char)
    local z = char:GetChildren()
    for i=1, #z do
        if (z[i].className == "Accessory") then
            z[i]:remove()
            print("removein")
            end
        end
        local verynewhat = game.ServerStorage.Hats:FindFirstChild(hat):clone()
    verynewhat.Parent = char
    char.Head.Mesh:remove()
     local newhead  = serverstorage.Hats.Mesh:clone()
    newhead.Parent = char.Head
end

function playeradded(player)
    print("hello")
    player:LoadCharacter()
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    local hat = Instance.new("StringValue")
    hat.Name = ("CurrentHat")
    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Parent = leaderstats
    leaderstats.Parent = player
    hat.Parent = player
    hat.Value = ds2:GetAsync(player.UserId) or math.floor(math.random(0,1))
    --table.insert(hattable, hat.Value)
--  ds3:SetAsync(player.UserId,hat.Value)
    --for index,value in pairs (hattable) do
   -- ds3:UpdateAsync(index, function() return value end)
    --end
    --print(hattable[1])
    --print(ds3)
    local playerHat = hat.value
    hat.Changed:connect(function()
    ds2:SetAsync(player.UserId,hat.Value)
    --ds3:SetAsync(player.UserId,table.insert(hat.Value))
    --print(ds3)
    end)
    coins.Value = ds1:GetAsync(player.UserId) or 0
    ds1:SetAsync(player.UserId,coins.Value)

    -- add infinite coins for me
    if player.Name == "R0boticalCat" then
        --coins.Value = 0
        --ds1:SetAsync(player.UserId,coins.Value)
    end

    coins.Changed:connect(function()
    ds1:SetAsync(player.UserId,coins.Value)
    end)
    player.CharacterAdded:connect(function(character)
        --addhat(player, playerHat)
        newcharacter(player, character)
    end)
    if player.Character and player.Character.Parent then
        --addhat(player, playerHat)
        newcharacter(player, player.character)
    end
    end
game.Players.PlayerAdded:connect(playeradded)

所有被注释掉的东西就是我想要做的。再一次,我想让您在购买帽子时为其添加库存gui,以便在购买时可以配备它,而不是替换当前保存的帽子并永久保存。

0 个答案:

没有答案