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

Data Store script will load, but not save anything in Filtering Enabled?

Asked by
soutpansa 120
6 years ago
Edited 6 years ago

I've got a Data Store script that someone made for me a few months ago because I was confused with how Data Stores worked. Now I've converted my game to FE, and there are only a few errors. Sadly, one of those errors is one of the most crucial parts of the game not working.

I tested the script by loading into the title screen place of my game and resetting the data with the new game button. All of my progress had reset and I was level 1. I rejoined the game, pressed load game, and I was still level 1. So good so far, then I changed my level to 5, waited one minute for the script to save my data, and loaded game again. I loaded in as level 1, which leads me to believe that the script is only not saving.

(the title screen place to the game is not Filtering Enabled, so thats how the data can reset and load into the normal place after pressing load game)

The script is a ServerScript inside of ServerScriptService.

Any help is appreciated, thanks a bunch for reading ^^

script:

local DSService = game:GetService('DataStoreService'):GetDataStore('JoJosJugsStorage')
ID = 65 --If you change this then it will reset everyones stats. [63],[67],[69],[68], [64],[65]
SaveTime = 60 --Shouldn't be less then 60
leaderboardname = "Levelss" --The name of the leader board

StatList = {Vampire = 0, Hamon = 0, Stamina = 100, MaxStamina = 100, Energy = 100, MaxEnergy = 100, Level = 1, XP = 0, CombatDamage = 1, SkillDamage = 1, Defense = 0, SendoKick = 0, TornadoOverdrive = 0, Overdrive = 0, Thunder = 0, Scarlet = 0, Yellow = 0 }
--StartingMoney would give new players the stat StartingMoney with the value 5
--Put any of your values here
--Values are loaded when the player joins and saved when they exit
--Values are also saved every SaveTime seconds

----- You shouldn't need to change anything below this line -----

function CreateValue(Name, Parent, Value) --If value is set to a number then new players will start with that amount.
    Value = Value or 0
    local savevalue =  Instance.new('IntValue', Parent)
    savevalue.Name = Name
    savevalue.Value = Value
    return savevalue
end

function GetValue(uniquekey)
    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        return GetSaved
    end
end

game.Players.PlayerAdded:connect(function(plr)
    local uniquekey = ID..plr.userId
    local Levelss = Instance.new('IntValue', plr)
    Levelss.Name = leaderboardname
    for i,v in pairs(StatList) do
        local Stat = GetValue(i..uniquekey)
        if Stat then
            CreateValue(i, Levelss, Stat) --Old player load their value
        else
            CreateValue(i, Levelss, v) --New player load the default value
        end
    end
end)

game.Players.PlayerRemoving:connect(function(plr)
    local uniquekey = ID..plr.userId
    if plr:FindFirstChild(leaderboardname) then
        for i,v in pairs(StatList) do
            if plr[leaderboardname]:FindFirstChild(i) then
                DSService:SetAsync(i..uniquekey, plr[leaderboardname][i].Value)
            end
        end
    end
end)

while wait(SaveTime) do
    P = game:GetService("Players"):GetChildren()
    for o=1, #P do
        if P[o] then
            local uniquekey = ID..P[o].userId
            if P[o]:FindFirstChild(leaderboardname) then
                for i,v in pairs(StatList) do
                    if P[o][leaderboardname]:FindFirstChild(i) then
                        DSService:SetAsync(i..uniquekey, P[o][leaderboardname][i].Value)
                    end
                end
            end
        end
    end
end

1 answer

Log in to vote
2
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago
Edited 6 years ago

When a player causes a change in the level, or xp make it Fire an remote event in the replicatedstorage or anywhere you keep it.

Also make an RemoteEvent in the replicatedstorage or where ever you want it

For ex: if a player press E to do a attack, in that script you will have the UIS or KeyDown, then you will write at the top :

local Event = game.writewhereyouwantit


Event:FireServer()

After doing all of that, make a script in the ServerScriptService and inside write the same local Event = game.writewhereyouwantit

Then you have to connect it with the remote event by doing this :

Event.OnServerEvent:connect(function(player)
--then write how the xp or level is changed
end)

You have to do this because when the xp or level is changed within the player, it isn't Replicated by the Server, so you need to use a RemoteEvent to make it be Replicated

0
Um.. I think that I already did this, when the player's XP reaches a certain amount, it fires the LevelUpEvent, then increases the stats. soutpansa 120 — 6y
0
I sorta understand though,for a stat inside of a player to be changed, it has to be Replicated. I'll play with it and get it to work eventually, you've put me on the correct path and that's all I needed, thanks soutpansa 120 — 6y
0
Np, glad to help :) oSyM8V3N 429 — 6y
Ad

Answer this question