Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Save script not saving?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

Try getting a new one

Ad

Answer this question