Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make these saves/loads work for universes?

-- Save 1

local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(Plr)
	Plr.Backpack.ChildAdded:connect(function(Item)
		if Plr.DataReady then
			for _, v in pairs(Plr.PlayerGui.Inventory.Frame.Items:GetChildren()) do
				if v ~= nil then
					Plr:SaveString(v.Name,v.Name)
				end
			end
		end
	end)
end)

Players.PlayerRemoving:connect(function(Plr)
	if Plr.DataReady then
		for _, v in pairs(Plr.PlayerGui.Inventory.Frame.Items:GetChildren()) do
			if v ~= nil then
				Plr:SaveString(v.Name,v.Name)
			end
		end
	end
end)

-- Load 1

game:GetService("Players").PlayerAdded:connect(function(Plr)
	Plr.CharacterAdded:connect(function(Char)
		Plr:WaitForDataReady()
		
		for _, v in pairs(game:GetService("ReplicatedStorage").Buttons:GetChildren()) do
			if Plr:LoadString(v.Name) == v.Name then
				print(Plr:LoadString(v.Name))
				cl = v:Clone()
				cl.Parent = Plr.PlayerGui.Inventory.Frame.Items
			end
		end
	end)
end) 

-- Save 2

local Stats = { ["Swordsmanship"] = 0, ["Cooking"] = 0, ["Blacksmithing"] = 0, ["Woodcutting"] = 0, ["Mining"] = 0, ["Beast Taming"] = 0, ["Foraging"] = 0, ["Alchemy"] = 0, ["Detection Skill"] = 0, ["Farming"] = 0, }

local SwordStats = { ["Short Blades"] = 0, ["Long Blades"] = 0, ["Great Blades"] = 0, ["Axes"] = 0, ["Rapiers"] = 0, ["Hammers"] = 0, ["Katanas"] = 0, ["Spears"] = 0, }

local Plr = script.Parent.Parent

local StatsDirectory = script.Parent.Parent.Stats local SwordStatsDirectory = script.Parent.Parent.SwordStats

repeat wait() until SwordStatsDirectory repeat wait() until StatsDirectory

function saveStats() for _, v in pairs(StatsDirectory:GetChildren()) do Plr:SaveNumber(v.Name,v.Value) end for _, v in pairs(SwordStatsDirectory:GetChildren()) do Plr:SaveNumber(v.Name,v.Value) end end

function updateStats() for _, v in pairs(StatsDirectory:GetChildren()) do Stats[v.Name] = v.Value end end

function updateSwordStats() for _, v in pairs(SwordStatsDirectory:GetChildren()) do SwordStats[v.Name] = v.Value end end

function loadData() for _, v in pairs(StatsDirectory:GetChildren()) do v.Value = Plr:LoadNumber(v.Name) or 0 updateStats() end for _, v in pairs(SwordStatsDirectory:GetChildren()) do v.Value = Plr:LoadNumber(v.Name) or 0 updateSwordStats() end end

for _, v in pairs(StatsDirectory:GetChildren()) do v.Changed:connect(function() updateStats() end) end

for _, v in pairs(SwordStatsDirectory:GetChildren()) do v.Changed:connect(function() updateSwordStats() end) end

My friend scripted these for me, mainly because I'm not good with any kind of data persistence (I understand them to an extent, just can't rewrite them) From what I've recently read, it's got something to do with Data Store and not Data Persistence.

1 answer

Use DataStores, Data Persistence will not transfer place to place in a universe. Need help with data stores? Click here to look at a tutorial on the Roblox official wiki.

This discussion is preserved as it was. New answers, comments, and votes are closed.