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

FilteringEnabled Data Stores (Saving Problem)?

Asked by 7 years ago
Edited 7 years ago

Hello, its been a while since I entered this site, but that's not important, since I'm stuck in a problem related to Data Stores.

So recently, I've kind of discovered by myself on how to save stats to Data Stores even with FilteringEnabled, it worked manually, but I want it so save/load automatically.

It worked with loading data, but for saving? Nah, won't work.

Heres the client sided script. (LocalScript, located on StarterGui)

local player = game.Players.LocalPlayer
local loadingevent = game.ReplicatedStorage:WaitForChild("LoadingEvent")
local savingalertevent = game.ReplicatedStorage:WaitForChild("SavingAlertEvent")
local savingevent = game.ReplicatedStorage:WaitForChild("SavingEvent")

loadingevent.OnClientEvent:connect(function(callname, datavalue, dataname)
    print(callname, datavalue, dataname)
    if callname == "DataLoading" then
        local lead = player:FindFirstChild("leaderstats")
        if lead then
            local valuetype = lead:FindFirstChild(dataname)
            if valuetype then
                valuetype.Value = datavalue
                local ddd = player:FindFirstChild("DataLoaded")
                if ddd then
                    ddd.Value = true
                    print("yes yes true")
                end
            end
        end
    end
end)
--[
game.Players.PlayerRemoving:connect(function(p)
    local thing = p:FindFirstChild("DataLoaded")
    if thing and thing.Value == true then
        local leader = p:FindFirstChild("leaderstats")

        if leader then
            local stats = leader:GetChildren()
            for i = 1, #stats do

                savingevent:FireServer("SaveGame", player.Name, stats[i].Name, stats[i].Value)
                print("saved")
            end
        end
    end
end)
--]]
-- Scrapped off junk
--[[
savingalertevent.OnClientEvent:connect(function(callname, statname)
    print(callname, statname)
    if callname == "DataSaving" then
        local lead = player:FindFirstChild("leaderstats")
        if lead then
            local valuefind = lead:FindFirstChild(statname)
            if valuefind then
                savingevent:FireServer("SaveGame", player.Name, valuefind.Name, valuefind.Value)
            end
        end
    end
end)
--]]

Now, here's the code from the server sided script. (Script, located on ServerScriptService)


function datastoreloadingfunc(player, leader) local stats = leader:GetChildren() for i = 1, #stats do local statvalue = datastore:GetAsync(stats[i].Name) loadingevent:FireClient(player, "DataLoading", statvalue, stats[i].Name) end end game.Players.PlayerAdded:connect(function(p) local leader = Instance.new("Folder", p) leader.Name = "leaderstats" local stat = Instance.new("NumberValue", leader) stat.Name = "Points" local dataloaded = Instance.new("BoolValue", p) dataloaded.Name = "DataLoaded" datastoreloadingfunc(p, leader) end) savingevents.OnServerEvent:connect(function(player, callname, playername, statname, statvalue) print(player, callname, playername, statname, statvalue) if callname == "SaveGame" then print("Saving... "..statvalue.." "..statvalue) datastore:SetAsync(statname, statvalue) print("Saved "..statvalue.." "..statvalue) end end)

Answers would be appreciated, thanks in advance.

0
You should put your localscript in starterPlayer. I think ReplicatedFirst objects get destroyed once the player is loaded, it's ment for custom loading screens. RubenKan 3615 — 7y
0
Placing it on StarterPlayer just disables the localscript from activating, but placing it on StarterPack/Gui solves the problem. Endermanium 25 — 7y

Answer this question