if not success or not savedData then print("No data found for key:", keyName) return end
-- Clear existing children (optional) for _, child in ipairs(instance:GetChildren()) do child:Destroy() end Roblox SaveInstance Script
if success then print("Saved instance to key:", keyName) else warn("Save failed:", err) end end if not success or not savedData then print("No
-- Function to save all children of an instance function SaveInstance(instance, keyName) local dataToSave = {} keyName) else warn("Save failed:"
-- Function to load saved data and rebuild instance function LoadInstance(instance, keyName) local success, savedData = pcall(function() return dataStore:GetAsync(keyName) end)
-- Save to DataStore local success, err = pcall(function() dataStore:SetAsync(keyName, dataToSave) end)