Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

Trying to save a folder inside a player, what's wrong?

Asked by
Raccoonyz 893 Donator Moderation Voter
7 months ago
Edited 7 months ago

Hi. I have a folder inside a player (not the character) and I want to save it in a datastore. However, it doesn't seem to work. I'm highly confused, any help?

local DS = game:GetService("DataStoreService"):GetDataStore("Items")
game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local folder = Instance.new("Folder")
    folder.Parent = plr
    folder.Name = "Folderitems"
    local plrkey = "id2_"..plr.userId
    local savevalue = folder:GetChildren()

    local GetSaved = DS:GetAsync(plrkey)
    if GetSaved then
        local input = GetSaved[1]
        local values = input:split("|")
for i = 1, #values do
    local number = Instance.new("NumberValue")
    number.Name = values[i]
    number.Parent = folder
end
    else
        local NumbersForSaving = {savevalue}
        DS:GetAsync(plrkey, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local savevalue = plr.Folderitems:GetChildren()
        local concat = table.concat(savevalue,"|")
    DS:SetAsync("id2_"..plr.userId, {concat})
end)

Right now I'm getting this error: ServerScriptService.DataStore2:27: invalid value (userdata) at index 1 in table for 'concat'

0
Are you attempting to use Datastore 2? Do you have the module script, because the error looks like a Datastore2 error. SteelMettle1 304 — 7mo
0
If you are, then you won't be able to use SetAsync and the module script will handle getting the "DataStoreService." SteelMettle1 304 — 7mo

1 answer

Log in to vote
0
Answered by 7 months ago

As im a little busy i cant help much but make sure api services are on and use this (this is a script from my game i didnt edit it as i dont want to screw it up as i also dont get data stores)

local DataStoreService = game:GetService("DataStoreService")
local PopularityDataStore = DataStoreService:GetDataStore("PopularityDataStoreExtremeAlpha")
local PopularityXPDataStore = DataStoreService:GetDataStore("PopularityXPDataStoreExtremeAlpha")

game.Players.PlayerAdded:Connect(function(Player)

    --  // Stats Folder
    local Stats = Instance.new("Folder")
    Stats.Name = "Stats"
    Stats.Parent = Player

    --  // PopularityLevel

    local PopularityLevel = Instance.new("IntValue")
    PopularityLevel.Parent = Stats
    PopularityLevel.Name = "Popularity"

    --  // PopularityXP

    local PopularityXP = Instance.new("IntValue")
    PopularityXP.Parent = Stats
    PopularityXP.Name = "PopularityXP"

    --  // Load Data

    --  // LvlData

    local LvlData
    local success, errormessage = pcall(function()
        LvlData = PopularityDataStore:GetAsync(Player.UserId.."-PopularityLvl")
    end)

    --  // XPData

    local XPData

    local success, errormessage = pcall(function()
        XPData = PopularityXPDataStore:GetAsync(Player.UserId.."-PopularityXP")

    if success then
        PopularityLevel.Value = LvlData
        PopularityXP.Value = XPData
    end
end)

game.Players.PlayerRemoving:Connect(function(Player2)

    --  // Save Data

    --  // PopularityLvl

    local success, errormessage = pcall(function()

        --  // PopularityXP

        PopularityDataStore:SetAsync(Player2.UserId.."-PopularityXP",Player2.Stats.PopularityLvl.Value)

        --  // PopularityLvl

        PopularityDataStore:SetAsync(Player2.UserId.."-PopularityLvl",Player2.Stats.PopularityXP.Value)

        --  // End
        end)    
    end)    
end)
0
If mine works please set it as the answer EnzoTDZ_YT 136 — 7mo
Ad

Answer this question