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

How do I reset the server data so everyone's data for this game is erased?

Asked by
flanfy -3
5 years ago

I want people to come back to this game as if they were a new player. Here is the Game Data Store Script, what should I change to make this possible?

config = game:GetService("ReplicatedStorage"):WaitForChild("GameConfig")
mod = game:GetService("ServerScriptService").GameRemoteHandler.NotifyEvent
serv = game:GetService("DataStoreService")
local Stats = serv:GetDataStore("StatsDS")
local Tools = serv:GetDataStore("ToolDS")

LoadData = function(plr,level,exp,gold,rebirths)
    -- Stats
    pcall(function()
        local GetData = Stats:GetAsync(plr.UserId)
        if GetData then
            level.Value = GetData[1]
            exp.Value = GetData[2]
            gold.Value = GetData[3]
            rebirths.Value = GetData[4]
        else
            level.Value = 1
            exp.Value = tonumber(nil)
            gold.Value = tonumber(nil)
            rebirths.Value = 1
        end
        -- Tools
        local ActualTools = {}
        local ToolStorage = require(config).ToolStorage
        if (Tools:GetAsync(plr.UserId)) then
            for _,v in pairs(Tools:GetAsync(plr.UserId)) do
                print(v)
                if ToolStorage:FindFirstChild(v) then
                    table.insert(ActualTools, v)
                end
            end
            for _,v in pairs(ActualTools) do
                ToolStorage:FindFirstChild(v):Clone().Parent = plr:WaitForChild("StarterGear")
                ToolStorage:FindFirstChild(v):Clone().Parent = plr:WaitForChild("Backpack")
            end
        end
        local DataLoadBoolean = Instance.new("BoolValue")
        DataLoadBoolean.Name = "DataLoaded"
        DataLoadBoolean.Parent = plr
    end)
end

SaveData = function(plr)
    -- Stats
    pcall(function()
        local lstats = plr:FindFirstChild("leaderstats")
        if (lstats~=nil) then
            local level = lstats:FindFirstChild("Level")
            local exp = lstats:FindFirstChild("XP")
            local gold = lstats:FindFirstChild("Gold")
            local rebirths = lstats:FindFirstChild("Rebirths")
            if (level~=nil) and (exp~=nil) and (gold~=nil) and (rebirths~=nil) then
                Stats:SetAsync(plr.UserId,{level.Value,exp.Value,gold.Value,rebirths.Value})
            end
        end
        -- Tools
        local ActualTools = {}
        local SG = plr:WaitForChild("StarterGear")
        for _,v in pairs(SG:GetChildren()) do
            table.insert(ActualTools, v.Name)
        end
        if ActualTools[1] then
            Tools:SetAsync(plr.UserId,ActualTools)
            warn(plr.. "'s data has been successfully saved.")
        end
    end)
end

game.Players.PlayerAdded:Connect(function(plr)

    local CanAutoSave = true
    local lstats = Instance.new("Folder",plr)
    lstats.Name = "leaderstats"

    local level = Instance.new("DoubleConstrainedValue",lstats)
    level.Name = "Level"
    level.MaxValue = require(config).Level_Max
    level.MinValue = 1

    local exp = Instance.new("DoubleConstrainedValue",lstats)
    exp.Name = "XP"
    exp.MaxValue = math.huge
    exp.MinValue = 0

    local gold = Instance.new("DoubleConstrainedValue",lstats)
    gold.Name = "Gold"
    gold.MaxValue = math.huge
    gold.MinValue = 0

    local rebirths = Instance.new("DoubleConstrainedValue",lstats)
    rebirths.Name = "Rebirths"
    rebirths.MaxValue = require(config).Rebirths_Max
    rebirths.MinValue = 0

    wait()

    pcall(function()
        LoadData(plr,level,exp,gold,rebirths)
    end)

    if require(config).ManualSaving then
        local PlayerGui = plr:WaitForChild("PlayerGui")
        plr.Chatted:Connect(function(str) 
            if str == ";save" then
                if (PlayerGui:FindFirstChild("ClientNotify")) then (PlayerGui:FindFirstChild("ClientNotify")):Destroy() end
                if (CanAutoSave) then
                    CanAutoSave = false
                    SaveData(plr)
                    require(mod).Notify(plr,"You successfully saved your data.")
                    wait(3*60)
                    CanAutoSave = true
                elseif (not CanAutoSave) then
                    require(mod).Notify(plr,"You cannot save due to data saving limitations, please try again in a few minutes.")
                end
            end
        end)
    end

    if require(config).AutomaticSaving then
        local C = nil
        if (not require(config).ManualSaving) then
            C = 10 else C = 5
        end
        while wait(C*60) do
            if (plr~=nil) then
                pcall(function()
                    SaveData(plr)
                end)
            else break
            end
        end
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    if (not plr) then return end
    pcall(function()
        if require(config).SaveOnExit then
            SaveData(plr)
        end
    end)
end)

local ServerTimeout = 5
game:BindToClose(function() 
    for _,v in pairs(game.Players:GetPlayers()) do
        if (v~=nil) then SaveData(v) end
    end
    wait(ServerTimeout) 
end)
1
For reset all data change data store key. yHasteeD 1819 — 5y

1 answer

Log in to vote
-1
Answered by
Kullaske 111
5 years ago
Edited 5 years ago

You can change the key for the GetAsync on line 10.

local GetData = Stats:GetAsync("AAAA"..plr.UserId)

Or, you can change the name of the datastore you load.

local Stats = serv:GetDataStore("StatsDS") -- Change the "StatsDS" to something like "StatsDS000" to wipe it
Ad

Answer this question