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

DataStore Doesn't Save, What's wrong?

Asked by 5 years ago

local Data = game:GetService('DataStoreService'):GetDataStore("DataStore") local Server = game:GetService('ReplicatedStorage'):FindFirstChild('Data')

game.Players.PlayerAdded:Connect(function(plr) local key = "id-"..plr.userId local test = Random.new() local data = Instance.new("Folder", Server) data.Name = "PlayerData-"..plr.UserId

local ExpNeeded =  Instance.new("IntValue", plr)
ExpNeeded.Name = "ExpNeeded"
ExpNeeded.Parent = data
ExpNeeded.Value = 50

local lv =  Instance.new("IntValue", plr)
lv.Name = "Level"
lv.Parent = data
lv.Value = 1

local MaxStamina = Instance.new("IntValue", data)
MaxStamina.Name = "MaxStamina"
MaxStamina.Value = 100

local CurrentStamina = Instance.new("IntValue", data)
CurrentStamina.Name = "CurrentStamina"
CurrentStamina.Value = MaxStamina.Value

local MaxEnergy = Instance.new("IntValue", data)
MaxEnergy.Name = "MaxEnergy"
MaxEnergy.Value = 100

local CurrentEnergy = Instance.new("IntValue", data)
CurrentEnergy.Name = "CurrentEnergy"
CurrentEnergy.Value = MaxEnergy.Value

local ex =  Instance.new("IntValue", plr)
ex.Name = "Exp"
ex.Parent = data
ex.Value = 0

local Okane =  Instance.new("IntValue", plr)
Okane.Name = "Okane"
Okane.Parent = data
Okane.Value = 0

local Str =  Instance.new("IntValue", plr)
Str.Name = "Strength"
Str.Parent = data
Str.Value = 0

local Ki =  Instance.new("IntValue", plr)
Ki.Name = "KiEnergy"
Ki.Parent = data
Ki.Value = 0

local sav = Data:GetAsync(key)
if sav then
    ----------------------
    lv.Value = sav[1]
    ex.Value = sav[2]
    MaxStamina.Value = sav[3]
    ExpNeeded.Value = sav[4]
    -------------------------
    Okane.Value = sav[5]
    Str.Value = sav[6]
    Ki.Value = sav[7]
    MaxEnergy.Value = sav[8]
    ----------------------
    CurrentEnergy.Value = MaxEnergy.Value
    CurrentStamina.Value = MaxStamina.Value
else
    local mj = {
        lv.Value, ex.Value, MaxStamina.Value, ExpNeeded.Value, Okane.Value,
        Str.Value, Ki.Value, MaxEnergy.Value
        }
    Data:SetAsync(key, mj)
end
-------------------------------------- AutoSave Events --------------------------------------
MaxStamina.Changed:Connect(function()
    local mj = {
        lv.Value, ex.Value, MaxStamina.Value, ExpNeeded.Value, Okane.Value,
        Str.Value, Ki.Value, MaxEnergy.Value
        }
    Data:SetAsync(key, mj)
end)
ex.Changed:Connect(function()
    local mj = {
        lv.Value, ex.Value, MaxStamina.Value, ExpNeeded.Value, Okane.Value,
        Str.Value, Ki.Value, MaxEnergy.Value
        }
    Data:SetAsync(key, mj)
end)
Str.Changed:Connect(function()
    local mj = {
        lv.Value, ex.Value, MaxStamina.Value, ExpNeeded.Value, Okane.Value,
        Str.Value, Ki.Value, MaxEnergy.Value
        }
    Data:SetAsync(key, mj)
end)
------------------------------------
Okane.Changed:Connect(function()
    local mj = {
        lv.Value, ex.Value, MaxStamina.Value, ExpNeeded.Value, Okane.Value,
        Str.Value, Ki.Value, MaxEnergy.Value
        }
    Data:SetAsync(key, mj)
end)
lv.Changed:Connect(function()
    local mj = {
        lv.Value, ex.Value, MaxStamina.Value, ExpNeeded.Value, Okane.Value,
        Str.Value, Ki.Value, MaxEnergy.Value
        }
    Data:SetAsync(key, mj)
end)

Ki.Changed:Connect(function()
    local mj = {
        lv.Value, ex.Value, MaxStamina.Value, ExpNeeded.Value, Okane.Value,
        Str.Value, Ki.Value, MaxEnergy.Value
        }
    Data:SetAsync(key, mj)
end)

MaxEnergy.Changed:Connect(function()
    local mj = {
        lv.Value, ex.Value, MaxStamina.Value, ExpNeeded.Value, Okane.Value,
        Str.Value, Ki.Value, MaxEnergy.Value
        }
    Data:SetAsync(key, mj)
end)

end)

game.Players.PlayerRemoving:Connect(function(plr) local key = 'id-'..plr.userId local atable = { Server['PlayerData-'..plr.UserId].Level.Value, Server['PlayerData-'..plr.UserId].MaxStamina.Value, Server['PlayerData-'..plr.UserId].ExpNeeded.Value, Server['PlayerData-'..plr.UserId].Okane.Value, Server['PlayerData-'..plr.UserId].Strength.Value, Server['PlayerData-'..plr.UserId].KiEnergy.Value, Server['PlayerData-'..plr.UserId].Exp.Value, Server['PlayerData-'..plr.UserId].MaxEnergy.Value } Data:SetAsync(key, atable) end)

0
Try a different script. There's a tutorial for a shorter but better one somewhere on Youtube. eloiishot 47 — 5y
0
no there isn't. Don't encourage bad practice/deprecated code containing videos. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Everything is wrong at this.

Ad

Answer this question