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

Save script not saving?

When someone resets, the stats save and load. But when someone rejoins, it just comes up as blank. There's no output, so I don't know what's going on. Can someone help?

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 = game:GetService("Players"):GetChildren()

local StatsDirectory = Plr.Stats
local SwordStatsDirectory = Plr.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

This is in ServerScriptService if that helps.

1 answer

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