Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I transfer inventory items between places within a game?

Asked by 3 years ago

I have a script that saves stats between places, but I'm newer to scripting and don't know how I'd go about doing the same with items in your inventory, including items that aren't in the starter pack. Here's the script I'm working with (not mine)

    --[[Savin'
            Dem
                Stats  
    --]]
    game.Players.PlayerRemoving:connect(function(player)
        local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")

    local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
    for i =  1, #statstorage do
        datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
        print("saved data number "..i)

    end
    print("Stats successfully saved")  
    end)


    --[[
        Loadin'
            Dem
                Stats
    --]]
    game.Players.PlayerAdded:connect(function(player)
            local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")

        player:WaitForChild("leaderstats")
        wait(1)
        local stats = player:FindFirstChild("leaderstats"):GetChildren()
        for i = 1, #stats do           
        stats[i].Value = datastore:GetAsync(stats[i].Name)
        print("stat numba "..i.." has been found")
            end
end)
0
TeleportService Itzlewis99 26 — 3y
0
could you elaborate on that? Idrk what I'm doing too well RobbyBobby2643 2 — 3y

Answer this question