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'
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)