#How do I get the name of a item in a table?

1 messages · Page 1 of 1 (latest)

reef summit
#

I'm making a shop system so that when you buy something an go into the main game, you get the item you got but I need to get the name of an item in a table and I'm kinda bad at scripting so pls help.

local currencyscript = require(game.ServerScriptService.CurrencyScript)
--Prices
local PotionPrice = 5000

local ShopService = {}

local DATASTORE_KEY = "Shop_01"

datastore2.Combine("DATA", DATASTORE_KEY)

--Shop

local Products = {
    "Potion",
    
}
local BoughtProducts = {
    ["Potion"] = false,
    
}

function ShopService:Buy(product, price, player)
    local ShopDataStore = datastore2(DATASTORE_KEY, player)
    if currencyscript:GetMoney(player) > price then return end
    for i, foundproduct in Products do
        if foundproduct == product then
            BoughtProducts[product] = true
            currencyscript:RemoveMoney(player, price)
            ShopDataStore:Set(BoughtProducts)
        end
    end
end

function ShopService:GetBoughtItems()
    return BoughtProducts
end

return ShopService```

```local shopService = require(game.ServerScriptService.ShopScript)
game.Players.PlayerAdded:Connect(function(player)
    for i, itembought in shopService:GetBoughtItems() do
        if itembought == true then
            for i, item in game.ServerStorage.Products:GetChildren() do
                
            end
        end
    end
    player.CharacterAdded:Connect(function(char)
        if player.UserId == 5227384076 then
            task.wait(10)
            local bladeofblood = game.ServerStorage.SpecialTools["The Blade of Blood"]:Clone()
            bladeofblood.Parent = player.Backpack
        end
    end)
end)```
reef summit
#

pls help

rough marsh
#

??? @reef summit

#

for i,v in Table do
Print(i.Name)
end

reef summit
#

ok

rough marsh
#

i is the position of what it is v is the object it self

#

for example

#

local Table = {"Big", "Hairy", "Balls"}
for i,v in Table do
Print(i) -- prints the number its in Big would be 1 Hairy 2 and Balls 3
Print(v) -- what it actually is so like big it would print big
end

reef summit
#

ik

#

im just stupid

rough marsh
#

nah your not it just takes time to learn its like a learning a new language for the first time its a struggle at first but the more you practice at it the easier it gets

visual sequoia