did not work, just has the value like usual
datastores is acutally hard can you try a datastore wrapper like DataStore2 and see if it works
so sorry, don’t know how to do that either… i’ve never used datastores before, only for this game because i’m very motivated to complete it
well it is easier to set it up than datastores
You could use a default “stand” value, at 0 at the start of your code. You could also use a key when pcalling for your datastore. If the player has no data, you give them the default stand value else give them the data that they already have.
Also couldn’t use just do
game.Players.PlayerAdded:Connect(function(Player)
local PlrStats = Instance.new("Folder")
PlrStats.Name = "PlrStats"
PlrStats.Parent = Player
local stand = Instance.new("StringValue")
Stand.Name = "Stand"
Stand.Value = 0
Stand.Parent = PlrStats
I think that’s a bit easier to work with.
ok, trying right now. i’ll let you know
oof it didn’t work again, i’ll try and figure something else out
did you enabled the API service?
I would do something along these lines, also you mentioned you were trying to save the folder? Do you mean the folder object? If so, I believe you aren’t able to save object values in DataStores.
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local GameData = DataStoreService:GetDataStore("GameData")
function saveData(Player, Data)
local Success, Error = pcall(function()
GameData:SetAsync(Player.UserId, Data)
end)
if Success then
print("Saved a player's data.")
else
warn(Error)
end
end
Players.PlayerAdded:Connect(function(Player)
local PlrStats = Instance.new("Folder", Player)
PlrStats.Name = "PlrStats"
local Stand = Instance.new("StringValue", PlrStats)
Stand.Name = "Stand"
Stand.Value = "Default" -- Set this to the default value you'd like to have
local Success, Stand = pcall(function()
local Stand = GameData:GetAsync(Player.UserId)
return Stand
end)
if Success then
print("Player data loaded.")
Stand.Value = Stand
else
warn(Stand)
end
end)
Players.PlayerRemoving:Connect(function(Player)
local PlrStats = Player:FindFirstChild("PlrStats")
local Data = nil
if PlrStats and PlrStats:FindFirstChild("Stand") then
Data = PlrStats.Stand.Value
end
if Data then
saveData(Player, Data)
end
end)
Yeah, I’m trying to save a folder located inside the player called “PlrStats”. Inside PlrStats is a value. I’m also trying to save a folder located in the player’s backpack, but the only thing that is saving is the PlrStats folder and the value inside of it.
Why do you need to save the folder if a new folder is created and parented to the player when they join?
Remember that Datastores don’t work in Roblox Studio, have you been testing it in the actual game?
Yes, I have. Doesn’t show there either
If you want to save everything inside the folder in the player’s backpack, you can simply loop through all tools for all players.
Players.PlayerRemoving:Connect(function(player)
for _Tool in pairs (player.Backpack.YOUR_FOLDER:GetChildren() do
-- Do stuff
This will help you out
I’m not saving tools, though. The reason a folder is in there is because I’m making an anime based game, and they are able to call out this “stand”. The stand is inside that folder, but it won’t save.
Then you could simply save the children of that folder. It doesn’t have to be tools.
Could you show an example? Like I said, I’m extremely new to data saving
alright, this is how I would do it. I wrote this in a rush, but it should get you pointed in the right direction.
local datastoreservice = game:GetService("DataStoreService")
local GameData = datastoreservice:GetDataStore("Data 1")
game.Players.PlayerAdded:Connect(function(Player)
local PlrStats = Instance.new("Folder",player)
PlrStats.Name = "PlrStats"
local plrdata
local success, errormsg = pcall(function()
local plrdata = GameData:GetAsync(player.UserId)
end)
if plrdata ~= nil then
if plrdata.PlrStats then
for i, v in pairs(GameData.PlrStats) do
local value = Instance.new("StringValue")
value.Name = "Stand"
value.Parent = PlrStats
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local GameData = {}
GameData.PlrStats= {}
for i, v in pairs(player.PlrStats:GetChildren()) do
table.insert(GameData.PlrStats, v.Name)
print(v.Name)
end
local success, errormsg = pcall(function()
GameData:SetAsync(player.UserId,GameData)
end)
if success then
print("your data was saved")
else
print("Data didn't save")
end
end)
hey again, sorry for the late reply, i’ll try asap