Hello, I want to datastore a folder. This folder has many contents in it and it would be tedious to use a lot of Instance.new() in my DataStore script, so want to save the folder aand it’s children. The folder is in ReplicatedStorage, by the way. Here’s my script.
local DataStoreService = game:GetService("DataStoreService") local playerData = DataStoreService:GetDataStore("OtherStats") local function onPlayerJoin(player) -- Runs when players join local otherstats = game.ReplicatedStorage.OtherStats local playerUserId = "Player_" .. player.UserId --Gets player ID local data = playerData:GetAsync(playerUserId) --Checks if player has stored data if data then local newstats = data['Stats'] newstats.Parent = player else local newcopy = otherstats:Clone() newcopy.Parent = player end end local function onPlayerExit(player) --Runs when players exit local savestats = player:FindFirstChild("OtherStats") local success, err = pcall(function() local playerUserId = "Player_" .. player.UserId playerData:SetAsync(playerUserId, savestats) --Saves player data end) if not success then warn('Could not save data!') end end game.Players.PlayerAdded:Connect(onPlayerJoin) game.Players.PlayerRemoving:Connect(onPlayerExit)
When I leave the game, I get the message “Could not save data!”
What’s wrong with my script or is it possible to save instances? I’m fairly sure It’s possible to save instances, after all, games like Blockate and Miners’ Haven datastore your builds.
yes, studio access to API services is enabled.